public ActionResult AddCardDetail()
        {
            CardDetail tmpObj = (CardDetail)TempData["CardDetail"];
            TempData["CardDetail"] = tmpObj;

            if (ModelState.IsValid)
            {
                CardDetail obj = new CardDetail();
                obj.token = tmpObj.token;
                obj.firstName = tmpObj.firstName;
                obj.lastName = tmpObj.lastName;
                obj.fullName = tmpObj.firstName + " " + tmpObj.lastName;
                obj.title = tmpObj.title;
                obj.description = tmpObj.description;
                obj.chargeFrequency = tmpObj.chargeFrequency;
                obj.CustomerId = tmpObj.CustomerId;
                obj.price = tmpObj.price;
                ViewBag.year = DBCommon.BindYear();
                ViewBag.month = DBCommon.BindMonth();
                ViewBag.CountryList = GetCountryList();
                //ViewBag.CustomerId = id;
                //obj.CustomerId = id;
                ViewBag.id = obj.CustomerId;
                ViewBag.email = TempData["email"];
                ViewBag.name = obj.fullName;
                ViewBag.date = DateTime.Now;
                return View(obj);
            }
            else
            {
                return View();
            }
        }
        public ActionResult AddCardDetail(CardDetail obj)
        {
            if (ModelState.IsValid)
            {
                obj.accountType = "credit-card";
                if (obj.cardNumber.StartsWith("4"))
                {
                    obj.cardType = "visa";
                }
                else if (obj.cardNumber.StartsWith("51") || obj.cardNumber.StartsWith("52") || obj.cardNumber.StartsWith("53") || obj.cardNumber.StartsWith("54") || obj.cardNumber.StartsWith("55"))
                {
                    obj.cardType = "master";
                }
                else if (obj.cardNumber.StartsWith("6011") || obj.cardNumber.StartsWith("65"))
                {
                    obj.cardType = "discover";
                }
                else if (obj.cardNumber.StartsWith("34") || obj.cardNumber.StartsWith("37"))
                {
                    obj.cardType = "american_express";
                }
                try
                {
                    //xml = "<payment>  <account-type>" + obj.accountType + "</account-type><credit-card><number>" + obj.cardNumber + "</number><card-type>" + obj.cardType.Trim() + "</card-type><verification-value>" + obj.verificationValue + "</verification-value><month>" + obj.month + "</month><year>" + obj.year + "</year> <first-name>" + obj.firstName + "</first-name><last-name>" + obj.lastName + "</last-name><address1>" + obj.BillingInfo.Address + "</address1><city>" + obj.BillingInfo.City + "</city><state>" + obj.BillingInfo.State + "</state><zip>" + obj.BillingInfo.Zip + "</zip><country>" + obj.BillingInfo.Country + "</country><phone-number>480-225-8217</phone-number></credit-card></payment>";
                    //xml = "<payment><account-type>credit-card</account-type><credit-card><number>" + obj.cardNumber + "</number><card-type>" + Request.Form["CardType"].ToString() + "</card-type><verification-Value>" + obj.verificationValue + "</verification-Value><month>" + obj.month + "</month><year>" + obj.year + "</year><first-name>" + obj.firstName + "</first-name><last-name>" + obj.lastName + "</last-name> <address1>" + obj.BillingInfo.Address + "</address1><city>" + obj.BillingInfo.City + "</city><state>" + obj.BillingInfo.State + "</state><zip>" + obj.BillingInfo.Zip + "</zip><country>"+obj.BillingInfo.Country+"</country></credit-card></payment>";
                    xml = "<payment>  <account-type>credit-card</account-type><credit-card><number>4222222222222</number><card-type>visa</card-type><verification-value>234</verification-value><month>1</month><year>2018</year> <first-name>" + obj.firstName + "</first-name><last-name>" + obj.lastName + "</last-name></credit-card></payment>";
                    site = ConfigurationManager.AppSettings["apiUrl"].ToString();
                    url = string.Format("https://subs.pinpayments.com/api/v4/{0}/invoices/", site);
                    string ErrorResponse = Payment(url + obj.token + "/pay.xml", xml, "PUT", obj.token);
                    var statuscode = ErrorResponse.Split('-')[0];
                    string message = ErrorResponse.Split('-')[1];
                    switch (statuscode)
                    {
                        case "404":
                            ModelState.AddModelError("PaymentError", message);
                            //ViewBag.PlanTitle = obj.title;
                            //ViewBag.description = obj.description;
                            //ViewBag.ChargeFrequency = obj.chargeFrequency;
                            //ViewBag.Price = obj.price;
                            ViewBag.year = DBCommon.BindYear();
                            ViewBag.month = DBCommon.BindMonth();
                            ViewBag.CountryList = GetCountryList();
                            return View(obj);
                        case "422":
                            ModelState.AddModelError("PaymentError", message);
                            //ViewBag.PlanTitle = obj.title;
                            //ViewBag.description = obj.description;
                            //ViewBag.ChargeFrequency = obj.chargeFrequency;
                            //ViewBag.Price = obj.price;
                            ViewBag.year = DBCommon.BindYear();
                            ViewBag.month = DBCommon.BindMonth();
                            ViewBag.CountryList = GetCountryList();
                            return View(obj);
                        case "403":
                            ModelState.AddModelError("PaymentError", message);
                            //ViewBag.PlanTitle = obj.title;
                            //ViewBag.description = obj.description;
                            //ViewBag.ChargeFrequency = obj.chargeFrequency;
                            //ViewBag.Price = obj.price;
                            ViewBag.year = DBCommon.BindYear();
                            ViewBag.month = DBCommon.BindMonth();
                            ViewBag.CountryList = GetCountryList();
                            return View(obj);
                        case "503":
                            ModelState.AddModelError("PaymentError", message);
                            //ViewBag.PlanTitle = obj.title;
                            //ViewBag.description = obj.description;
                            //ViewBag.ChargeFrequency = obj.chargeFrequency;
                            //ViewBag.Price = obj.price;
                            ViewBag.year = DBCommon.BindYear();
                            ViewBag.month = DBCommon.BindMonth();
                            ViewBag.CountryList = GetCountryList();
                            return View(obj);
                        case "NotFound":
                            ModelState.AddModelError("PaymentError", "Plan is not exists in database");
                            //ViewBag.PlanTitle = obj.title;
                            //ViewBag.description = obj.description;
                            //ViewBag.ChargeFrequency = obj.chargeFrequency;
                            //ViewBag.Price = obj.price;
                            ViewBag.year = DBCommon.BindYear();
                            ViewBag.month = DBCommon.BindMonth();
                            ViewBag.CountryList = GetCountryList();
                            message = "Plan is not exists in database";
                            return View(obj);
                    }
                    if (statuscode == "404" || statuscode == "422" || statuscode == "422" || statuscode == "403")
                    {
                        ModelState.AddModelError("PaymentError", message);
                    }

                    CustomerModel model = new CustomerModel();
                    model.ValidateCustomerID(obj.CustomerId);
                    ViewBag.id = obj.CustomerId;
                    ViewBag.email = TempData["PrimaryEmail"];
                    return RedirectToAction("ThankYou");
                }
                catch (WebException ex)
                {
                    return View("PaymentFail");
                }
            }
            else
            {
                ViewBag.year = DBCommon.BindYear();
                ViewBag.month = DBCommon.BindMonth();
                //ViewBag.PlanTitle = obj.title;
                //ViewBag.description = obj.description;
                //ViewBag.ChargeFrequency = obj.chargeFrequency;
                //ViewBag.Price = obj.price;
                ViewBag.CountryList = GetCountryList();
                return View();
            }
        }
        public ActionResult CreateSubscriber(SiteSubscriber obj)
        {
            if (ModelState.IsValid)
            {
                Guid guid = new Guid();
                Random rnmd = new Random();
                ULDEntities db = new ULDEntities();
                if (ModelState.IsValid)
                {
                    ULDCustomer.Models.ULDCustomer obtbl = new ULDCustomer.Models.ULDCustomer();
                    CustomerModel model = new CustomerModel();
                    int cutomerid = model.AddCustomer(obj);
                    xml = "<subscriber><customer-id>" + cutomerid + "</customer-id><screen-name>" + obj.FirstName + obj.LastName + "</screen-name></subscriber>";
                    site = ConfigurationManager.AppSettings["apiUrl"].ToString();
                    url = string.Format("https://subs.pinpayments.com/api/v4/{0}/subscribers.xml", site);
                    CreateSubscriberApi(url, xml, "Post");
                    CardDetail obj1 = new CardDetail();

                    obj1.token = GenrateInvoice(obj.SubscriptionId, cutomerid.ToString(), obj.FirstName, obj.Email);
                    obj1.firstName = obj.FirstName;
                    obj1.lastName = obj.LastName;
                    obj1.fullName = obj.FirstName + " " + obj.LastName;
                    var planDetail = DBCommon.GetPlanDetailByProductID(obj.SubscriptionId);
                    obj1.title = planDetail.Rows[0]["title"].ToString();
                    obj1.CustomerId = cutomerid;
                    obj1.description = planDetail.Rows[0]["description"].ToString();
                    obj1.price = planDetail.Rows[0]["price"].ToString();
                    ViewBag.year = DBCommon.BindYear();
                    ViewBag.month = DBCommon.BindMonth();
                    TempData["CardDetail"] = obj1;
                    TempData["email"] = obj.Email;
                    TempData["PrimaryEmail"] = obj.Email;
                    //   return RedirectToAction("AddCardDetail", new { id = cutomerid });
                    return RedirectToAction("AddCardDetail");
                }
                return View("CreateSubscriber");
            }
            else
            {
                return View(obj);
            }
        }