コード例 #1
0
        public ActionResult GetPaymentMethods()
        {
            int id = 0;

            Int32.TryParse(Request.Form["productId"], out id);

            Product product = db.Products.First(m => m.ID == (id));

            if (product != null)
            {
                PriceSetting ps     = new PriceSetting(product.PriceSettingId);
                string       locale = Request.Form["language"] + "-" + Request.Form["country"];
                ps.LOCALE = locale;
                PaymentMethodResponse paymentObject = ps.ListPaymentMethods();

                if (paymentObject.RESPONSE.ContainsKey("error"))
                {
                    return(Json(new { success = false, message = "Error" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    List <Hashtable> paymentMethods = paymentObject.PaymentMethods();
                    return(PartialView("_PaymentMethodButtons", paymentMethods));
                }
            }
            else
            {
                return(Json(new { success = false, message = "Error" }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public ActionResult GetPaymentMethods()
        {
            int id = 0;
            Int32.TryParse(Request.Form["productId"], out id);

            Product product = db.Products.First(m => m.ID == (id));

            if (product != null)
            {
                PriceSetting ps = new PriceSetting(product.PriceSettingId);
                string locale = Request.Form["language"] + "-" + Request.Form["country"];
                ps.LOCALE = locale;
                PaymentMethodResponse paymentObject = ps.ListPaymentMethods();

                if (paymentObject.RESPONSE.ContainsKey("error"))
                {
                    return Json(new { success = false, message = "Error" }, JsonRequestBehavior.AllowGet);

                }
                else
                {
                    List<Hashtable> paymentMethods = paymentObject.PaymentMethods();
                    return PartialView("_PaymentMethodButtons", paymentMethods);
                }
            }
            else
            {
                return Json(new { success = false, message = "Error" }, JsonRequestBehavior.AllowGet);
            }

        }
コード例 #3
0
 protected void SetUp()
 {
     expectedHash         = new Hashtable();
     ps                   = Substitute.For <PriceSetting>(111, "thekey");
     ps.PAYALOGUE_ID      = 111;
     ps.LOCALE            = "nl-NL";
     ps.PAYMENT_METHOD_ID = 2;
 }
コード例 #4
0
ファイル: PriceSettingTest.cs プロジェクト: ashahzad4/Zaypay
 protected void SetUp()
 {
     expectedHash = new Hashtable();
     ps = Substitute.For<PriceSetting>(111, "thekey");
     ps.PAYALOGUE_ID = 111;
     ps.LOCALE = "nl-NL";
     ps.PAYMENT_METHOD_ID = 2;
 }
コード例 #5
0
        /// <summary>
        /// 商品排行
        /// </summary>
        /// <param name="nameKeyword">关键字</param>
        /// <param name="categoryId">类别id</param>
        /// <param name="sortBy">排序</param>
        /// <param name="maxPrice">某个区间的最大价格</param>
        /// <param name="minPrice">某个区间的最小价格</param>
        /// <param name="pageSize">每页多少条</param>
        /// <param name="pageIndex">第几页</param>
        /// <returns></returns>
        public ActionResult Rank(string nameKeyword = null, long?categoryId = null, SortBy_PointGift sortBy = SortBy_PointGift.Sales_Desc, int maxPrice = 0, int minPrice = 0, int pageSize = 20, int pageIndex = 1)
        {
            //获取用户配置的价格区间
            Dictionary <int, int> price = PriceSetting.Get();

            ViewData["price"] = price;

            pageResourceManager.InsertTitlePart("商品排行");

            //获取类别
            IEnumerable <Category> childCategories = null;

            if (categoryId.HasValue && categoryId.Value > 0)
            {
                var category = categoryService.Get(categoryId.Value);
                if (category != null)
                {
                    if (category.ChildCount > 0)
                    {
                        childCategories = category.Children;
                    }
                    else//若是叶子节点,则取同辈分类
                    {
                        if (category.Parent != null)
                        {
                            childCategories = category.Parent.Children;
                        }
                    }
                    List <Category> allParentCategories = new List <Category>();

                    //递归获取所有父级类别,若不是叶子节点,则包含其自身
                    RecursiveGetAllParentCategories(category.ChildCount > 0 ? category : category.Parent, ref allParentCategories);
                    ViewData["allParentCategories"] = allParentCategories;
                    ViewData["currentCategory"]     = category;
                }
            }

            if (childCategories == null)
            {
                childCategories = categoryService.GetRootCategories(TenantTypeIds.Instance().PointGift());
            }

            ViewData["childCategories"] = childCategories;

            PagingDataSet <PointGift> gifts = pointMallService.GetGifts(nameKeyword, categoryId, sortBy, maxPrice, minPrice, pageSize, pageIndex);

            return(View(gifts));
        }
        public ActionResult Reporting()
        {
            NameValueCollection parameters = Request.QueryString;

            //check if all required params are there
            if (AllValuesPresent(parameters))
            {

                int priceSettingId = Convert.ToInt32(parameters["price_setting_id"]);
                int paymentId = Convert.ToInt32(parameters["payment_id"]);
                int purchaseId = Convert.ToInt32(parameters["purchase_id"]);

                Purchase purchase  = db.Purchases.Find(purchaseId);
                if (purchase != null && (purchase.ZaypayPaymentId == paymentId))
                {

                    Product product = purchase.Product;

                    if (product.PriceSettingId == priceSettingId)
                    {

                        // get the key from the xml file
                        PriceSetting ps = new PriceSetting(product.PriceSettingId);

                        PaymentResponse response = ps.ShowPayment(purchase.ZaypayPaymentId);

                        string status = response.Status();

                        if (status == parameters["status"])
                        {
                            purchase.NeedPolling = SetNeedPollingValue(ref response);
                            purchase.Status = status;
                            db.SaveChanges();
                        }
                    }

                }
                else
                {
                    logEntry.Message = "Reporting Method in Products Controller ----  Values are missing --- the request had following query string :: " + parameters;
                    Logger.Write(logEntry);
                    System.Diagnostics.Debug.WriteLine("zayapy payment id is MiSSING");
                }

            }

            return Content("*ok*");
        }
コード例 #7
0
        public ActionResult Reporting()
        {
            NameValueCollection parameters = Request.QueryString;

            //check if all required params are there
            if (AllValuesPresent(ref parameters))
            {
                int priceSettingId = 0;
                int paymentId      = 0;
                int purchaseId     = 0;
                int payalogueId    = 0;

                Int32.TryParse(parameters["price_setting_id"], out priceSettingId);
                Int32.TryParse(parameters["payment_id"], out paymentId);
                Int32.TryParse(parameters["purchase_id"], out purchaseId);
                Int32.TryParse(parameters["payalogue_id"], out payalogueId);

                Purchase purchase = db.Purchases.Find(purchaseId);
                if (purchase != null && (purchase.ZaypayPaymentId == paymentId))
                {
                    Product product = purchase.Product;

                    if (product.PriceSettingId == priceSettingId && product.PayalogueId == payalogueId)
                    {
                        PriceSetting ps = new PriceSetting(product.PriceSettingId);

                        PaymentResponse response = ps.ShowPayment(purchase.ZaypayPaymentId);
                        string          status   = response.Status();

                        if (status == parameters["status"])
                        {
                            purchase.Status = status;
                            db.SaveChanges();
                        }
                    }
                }
            }
            else
            {
                LogEntry("Reporting Method in Purchase Controller ----  Values are missing --- the request had following query string :: " + parameters);
                System.Diagnostics.Debug.WriteLine("VAL NOT PRESENT");
            }
            return(Content("*ok*"));
        }
コード例 #8
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         var price = new PriceSetting();
         price.generalparcelID = Convert.ToInt32(Request.Form["GeneralParcel"]);
         price.perunitprice    = Convert.ToDecimal(Request.Form["PerUnitPrice"]);
         price.AskedPrice      = Convert.ToDecimal(Request.Form["AskedPrice"]);
         price.ParcelNo        = db.GeneralInfoParcels.Where(m => m.Id == price.generalparcelID).FirstOrDefault().ParcelNo;
         db.PriceSetting.Add(price);
         db.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception e)
     {
         TempData["error"] = "Price Setting Already Exits";
         return(RedirectToAction(nameof(Index)));
     }
 }
        public ViewResult Details(int id = 0)
        {
            //System.Diagnostics.Debug.WriteLine("IN DETAIS WITH ID------------------: " + id);

            Purchase purchase = db.Purchases.Find(id);

            if (purchase != null && purchase.SessionId == HttpContext.Session.SessionID)
            {

                PriceSetting ps = new PriceSetting(purchase.Product.PriceSettingId);

                PaymentResponse payment = ps.ShowPayment(purchase.ZaypayPaymentId);

                string status = payment.Status();
                int paymentMethodId = payment.PaymentMethodId();

                Hashtable instructions = payment.Instructions();

                ViewData.Add("instructions", instructions["long-instructions"]);

                ViewData.Add("status", status);
                ViewData.Add("payment_method_id", paymentMethodId);

                ViewData.Add("verification_needed", payment.VerificationNeeded());
                ViewData.Add("verification_tries_left", payment.VerificationTriesLeft());
                ViewData.Add("payment_id", purchase.ZaypayPaymentId);

                return View(purchase);
            }
            else
            {
                throw new HttpException(404, "Sorry, Resource not available");
            }
        }
コード例 #10
0
        public ActionResult Create(int productId = 0)
        {

            //Product product = db.Products.First(m => m.ID == productId);
            Product product = db.Products.Find(productId);

            if (product != null)
            {
                try
                {
                    PriceSetting ps = new PriceSetting(product.PriceSettingId);

                    //check if locale is supported 
                    string userIp = GetUserIP();
                    string locale = "";
                    string[] locales = "en-".Split('-');

                    ListLocalesResponse localesList = ps.ListLocales();
                    
                    //if we have correct user ip
                    if (!String.IsNullOrWhiteSpace(userIp))
                    {
                        LocalForIPResponse localeResponse = ps.LocaleForIP(userIp);
                        locale = localeResponse.Locale();

                        ps.LOCALE = locale;
                        locales = locale.Split('-');

                        if (localesList.CountrySupported(locales[1]))
                        {
                            List<Hashtable> paymentMethods = ps.ListPaymentMethods().PaymentMethods();
                            ViewData.Add("paymentMethods", paymentMethods);
                        }
                    }
                    else
                    {
                        ViewData["ipIsNull"] = true;
                    }

                    var countriesHash = (List<Hashtable>)localesList.Countries();
                    var languagesHash = (List<Hashtable>)localesList.Languages();

                    List<SelectListItem> countriesList = GetCountries(ref countriesHash);
                    countriesList = countriesList.OrderBy(x => x.Text).ToList();

                    List<SelectListItem> languagesList = GetLanguages(ref languagesHash);
                    languagesList = languagesList.OrderBy(x => x.Text).ToList();

                    ViewData.Add("countries", new SelectList(countriesList, "Value", "Text", locales[1]));
                    ViewData.Add("languages", new SelectList(languagesList, "Value", "Text", locales[0]));

                    if (TempData["error"] != null)
                        ViewData["error"] = TempData["error"];

                    return View(product);
                }
                catch (Exception e)
                {
                    string mesg = GetExceptionMessage(e);

                    if (mesg == "")
                        throw e;
                    else
                    {
                        LogEntry(e.Message);
                        ViewData["error"] = mesg;
                        return View("../products/index", db.Products.ToList());
                    }
                }
                
            }
            else
            {
                throw new HttpException(404, "Sorry, Resource not available");
            }

        }
        public ActionResult GetStatus()
        {
            int id = 0;
            Int32.TryParse(Request.Form["purchaseId"], out id);

            Purchase purchase = db.Purchases.Find(id);

            if (PurchaseIsCorrect(ref purchase))
            {

                if (purchase.Status == "prepared" || (purchase.Status == "in_progress" && purchase.NeedPolling == 0))
                {
                    return Json(new { status = purchase.Status }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    if (purchase.NeedPolling == 1)
                    {
                        PriceSetting ps = new PriceSetting(purchase.Product.PriceSettingId);

                        PaymentResponse payment = ps.ShowPayment(purchase.ZaypayPaymentId);

                        ViewData.Add("instructions", ((Hashtable)payment.Instructions())["long-instructions"]);
                        ViewData.Add("verification_needed", payment.VerificationNeeded());
                        ViewData.Add("verification_tries_left", payment.VerificationTriesLeft());
                        return PartialView("_PaymentScreen", purchase);

                    }
                    return PartialView("_PaymentScreen", purchase);

                }

            }
            else
            {
                return Json(new { success = false, message = "Error" }, JsonRequestBehavior.AllowGet);
            }
        }
コード例 #12
0
        public ActionResult Create(FormCollection form)
        {

            int productId = 0;
            int paymentMethodId = 0;

            Int32.TryParse(form["productId"], out productId);

            Product product = db.Products.Find(productId);

            if (product != null)
            {
                if (Int32.TryParse(form["paymentMethod"], out paymentMethodId) && form["languagesList"] != null && form["countriesList"] != null)
                {
                    Purchase purchase = null;

                    try
                    {

                        PriceSetting ps = new PriceSetting(product.PriceSettingId);
                           
                        string locale = form["languagesList"] + "-" + form["countriesList"];

                        ps.LOCALE = locale;
                        ps.PAYMENT_METHOD_ID = paymentMethodId;
                        ps.PAYALOGUE_ID = product.PayalogueId;

                        purchase = CreatePurchase(product);
                        
                        NameValueCollection options = new NameValueCollection();
                        options.Add("purchase_id", purchase.ID.ToString());
                        PaymentResponse payment = ps.CreatePayment(options);

                        purchase.Update(payment);
                        db.SaveChanges();

                        return Redirect("https://secure.zaypay.com" + payment.PayalogueUrl());

                    }
                    catch (Exception e)
                    {
                        string mesg = GetExceptionMessage(e);

                        if (purchase != null)
                            RemovePurchase(ref purchase);

                        if (mesg == "")
                            throw e;
                        else
                        {
                            LogEntry(e.Message);
                            TempData["error"] = mesg;
                            return RedirectToAction("Create", new { productId = product.ID });
                        }
                    }

                }
                else
                {
                    TempData["error"] = "Language , Country or Payment Method is not selected properly";
                    return RedirectToAction("Create", new { productId = product.ID });
                }
            }
            else
            {
                throw new HttpException(404, "Sorry, Resource Not Found");
            }

            //return RedirectToAction("Details",new { id = purchase.ID});


        }
コード例 #13
0
        public ActionResult Reporting()
        {

            NameValueCollection parameters = Request.QueryString;
            
            //check if all required params are there
            if (AllValuesPresent(ref parameters))
            {
                
                int priceSettingId = 0;
                int paymentId = 0;
                int purchaseId = 0;
                int payalogueId = 0;

                Int32.TryParse(parameters["price_setting_id"], out priceSettingId);
                Int32.TryParse(parameters["payment_id"], out paymentId);
                Int32.TryParse(parameters["purchase_id"], out purchaseId);
                Int32.TryParse(parameters["payalogue_id"], out payalogueId);

                Purchase purchase = db.Purchases.Find(purchaseId);
                if (purchase != null && (purchase.ZaypayPaymentId == paymentId))
                {
                
                    Product product = purchase.Product;

                    if (product.PriceSettingId == priceSettingId && product.PayalogueId == payalogueId)
                    {
                
                        PriceSetting ps = new PriceSetting(product.PriceSettingId);

                        PaymentResponse response = ps.ShowPayment(purchase.ZaypayPaymentId);
                        string status = response.Status();
                
                        if (status == parameters["status"])
                        {                            
                            purchase.Status = status;
                            db.SaveChanges();

                        }
                    }

                }

            }
            else
            {
                LogEntry("Reporting Method in Purchase Controller ----  Values are missing --- the request had following query string :: " + parameters);
                System.Diagnostics.Debug.WriteLine("VAL NOT PRESENT");
            }
            return Content("*ok*");

        }
コード例 #14
0
        public static void SetScaleCalculationNote(this CalculationModel model, PriceSetting priceSetting, int starItemtOrderID)
        {
            //price scale id start by 1
            for (int i = 1; i <= model.GeneralSetting.PriceScale.Scale; i++)
            {
                int iOrder = starItemtOrderID;

                CalculationNoteModel oItem = new CalculationNoteModel()
                {
                    ID = i,
                    CalculationItems = new List <CalculationItemModel>(),
                    //CalculationMarginItems = new List<CalculationItemModel>()
                };
                model.CalculationNotes.Add(oItem);

                //group4
                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign        = "+",
                    Description = "Gewinnaufschlag",
                    Tag         = "GA",
                    Currency    = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    BaseCalculationGroupRows = new List <int>()
                    {
                        0, 1, 2, 3
                    },
                    Group     = 4,
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null
                });

                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign        = "=",
                    Description = "Barverkaufspreis",
                    Tag         = "VK(bar)",
                    Currency    = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    Group         = 4,
                    IsSummary     = true,
                    SummaryGroups = new List <int>()
                    {
                        0, 1, 2, 3, 4
                    },
                    CostCalculatonGroup = new CostCalculatonGroupModel()
                    {
                        BaseCalculationGroupRows = new List <int>()
                        {
                            5
                        },
                        SummaryGroups = new List <int> {
                            5
                        },
                    },
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null
                });


                //group5
                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign          = "+",
                    Description   = "Kundenskonto",
                    AmountPercent = priceSetting.CashDiscount,
                    Tag           = "SKT",
                    Currency      = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    BaseCalculationGroupRows = new List <int>()
                    {
                        0, 1, 2, 3, 4
                    },
                    Group     = 5,
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null,
                    EditedField = "P"
                });

                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign          = "+",
                    Description   = "Verhandlungsspielraum",
                    AmountPercent = priceSetting.SalesBonus,
                    Tag           = "PV",
                    Currency      = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    BaseCalculationGroupRows = new List <int>()
                    {
                        0, 1, 2, 3, 4
                    },
                    Group     = 5,
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null,
                    EditedField = "P"
                });

                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign        = "=",
                    Description = "Zielverkaufspreis",
                    Tag         = "VK(ziel)",
                    Currency    = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    Group         = 5,
                    IsSummary     = true,
                    SummaryGroups = new List <int>()
                    {
                        0, 1, 2, 3, 4, 5
                    },
                    CostCalculatonGroup = new CostCalculatonGroupModel()
                    {
                        BaseCalculationGroupRows = new List <int>()
                        {
                            6
                        },
                        SummaryGroups = new List <int> {
                            6
                        },
                    },
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null
                });


                //group6
                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign          = "+",
                    Description   = "Kundenrabatt",
                    AmountPercent = priceSetting.CustomerDiscount,
                    Tag           = "RBT",
                    Currency      = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    BaseCalculationGroupRows = new List <int>()
                    {
                        0, 1, 2, 3, 4, 5
                    },
                    Group     = 6,
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null,
                    EditedField = "P"
                });

                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign        = "=",
                    Description = "Nettoverkaufspreis",
                    Tag         = "VK(liste)",
                    Currency    = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    Group         = 6,
                    IsSummary     = true,
                    SummaryGroups = new List <int>()
                    {
                        0, 1, 2, 3, 4, 5, 6
                    },
                    CostCalculatonGroup = new CostCalculatonGroupModel()
                    {
                        BaseCalculationGroupRows = new List <int>()
                        {
                            7
                        },
                        SummaryGroups = new List <int> {
                            7
                        },
                    },
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null
                });


                //group7
                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign          = "+",
                    Description   = "Mehrwertsteuer",
                    AmountPercent = priceSetting.VatTaxes,
                    Tag           = "MWST",
                    Currency      = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    BaseCalculationGroupRows = new List <int>()
                    {
                        0, 1, 2, 3, 4, 5, 6
                    },
                    Group     = 7,
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null,
                    EditedField = "P"
                });

                iOrder += 1;
                oItem.CalculationItems.Add(new CalculationItemModel()
                {
                    Sign        = "=",
                    Description = "Bruttoverkaufspreis",
                    Tag         = "VK(brutto)",
                    Currency    = new CurrencyModel()
                    {
                        Currency = "CHF"
                    },
                    Group         = 7,
                    IsSummary     = true,
                    SummaryGroups = new List <int>()
                    {
                        0, 1, 2, 3, 4, 5, 6, 7
                    },
                    ItemOrder = iOrder,
                    Convert   = model.GeneralSetting.Convert.Mode == "E" ? new ConvertModel()
                    {
                        Unit = "EE"
                    } : null
                });
            }
        }
コード例 #15
0
        public ActionResult Reporting()
        {
            NameValueCollection parameters = Request.QueryString;

            int priceSettingId = 0;
            int paymentId = 0;
            int productId = 0;
            int payalogueId = 0;

            Int32.TryParse(parameters["price_setting_id"], out priceSettingId);
            Int32.TryParse(parameters["payment_id"], out paymentId);
            Int32.TryParse(parameters["product_id"], out productId);
            Int32.TryParse(parameters["payalogue_id"], out payalogueId);

            System.Diagnostics.Debug.WriteLine("params are " + parameters);

            if (AllValuesPresent(ref parameters))
            {
                Product product = db.Products.Find(productId);
                System.Diagnostics.Debug.WriteLine("all val present");

                if (product != null && product.PriceSettingId == priceSettingId && product.PayalogueId == payalogueId)
                {

                    System.Diagnostics.Debug.WriteLine("prod is god, and ps id is good an payaid is good");

                    try
                    {
                        PriceSetting ps = new PriceSetting(product.PriceSettingId);
                        PaymentResponse payment = ps.ShowPayment(paymentId);

                        string status = payment.Status();

                        if (status == parameters["status"])
                        {

                            Purchase purchase = db.Purchases.FirstOrDefault(x => x.ZaypayPaymentId == paymentId);

                            if (purchase == null)
                            {
                                purchase = new Purchase(paymentId, product);
                                db.Purchases.Add(purchase);
                            }
                            else
                                purchase.Update(status);

                            db.SaveChanges();

                        }

                    }
                    catch (Exception ex)
                    {
                        LogEntry(ex.Message);
                        System.Diagnostics.Debug.WriteLine("Some exception ocured");
                    }

                }
            }

            return Content("*ok*");
        }
        public ActionResult SubmitVerificationCode()
        {
            int id = 0;
            Int32.TryParse(Request.Form["purchaseId"], out id);

            int code = 0;
            Int32.TryParse(Request.Form["code"], out code);

            Purchase purchase = db.Purchases.Find(id);

            if (purchase != null && purchase.SessionId == HttpContext.Session.SessionID)
            {
                if (code != 0)
                {
                    try
                    {

                        PriceSetting ps = new PriceSetting(purchase.Product.PriceSettingId);
                        PaymentResponse payment = ps.VerificationCode(purchase.ZaypayPaymentId, Request.Form["code"]);

                        purchase.Status = payment.Status();

                        SetViewData(ref payment);
                        return PartialView("_PaymentScreen", purchase);

                    }
                    catch (Exception e)
                    {
                        LogEntry(e.Message);
                        return Json(new { success = false, redirect = false, message = "Oops!! Some error occured" }, JsonRequestBehavior.AllowGet);
                    }
                }
                else
                {
                    return Json(new { success = false, redirect = false, message = "Code cannot be empty and it cannot contian string literals" }, JsonRequestBehavior.AllowGet);
                }

            }
            else
            {
                return Json(new { success = false, redirect = true, message = "You are not authorized. Redirecting ...." }, JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult GetPaymentMethods()
        {
            int id = 0;
            Int32.TryParse(Request.Form["productId"], out id);

            Product product = db.Products.First(m => m.ID == (id));

            if (product != null)
            {
                try
                {
                    PriceSetting ps = new PriceSetting(product.PriceSettingId);
                    string locale = Request.Form["language"] + "-" + Request.Form["country"];
                    ps.LOCALE = locale;
                    PaymentMethodResponse paymentObject = ps.ListPaymentMethods();

                    List<Hashtable> paymentMethods = paymentObject.PaymentMethods();

                    return PartialView("_PaymentMethodButtons", paymentMethods);

                }
                catch (Exception ex)
                {
                    LogEntry(ex.Message);
                    return Json(new { success = false, message = "Some error occured while retrieving the payment methods , try again !!" }, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(new { success = false, message = "You are not authorized to make this call" }, JsonRequestBehavior.AllowGet);
            }
        }
コード例 #18
0
        public ActionResult Create(int productId = 0)
        {
            //Product product = db.Products.First(m => m.ID == productId);
            Product product = db.Products.Find(productId);

            if (product != null)
            {
                try
                {
                    PriceSetting ps = new PriceSetting(product.PriceSettingId);

                    //check if locale is supported
                    string   userIp  = GetUserIP();
                    string   locale  = "";
                    string[] locales = "en-".Split('-');

                    ListLocalesResponse localesList = ps.ListLocales();

                    //if we have correct user ip
                    if (!String.IsNullOrWhiteSpace(userIp))
                    {
                        LocalForIPResponse localeResponse = ps.LocaleForIP(userIp);
                        locale = localeResponse.Locale();

                        ps.LOCALE = locale;
                        locales   = locale.Split('-');

                        if (localesList.CountrySupported(locales[1]))
                        {
                            List <Hashtable> paymentMethods = ps.ListPaymentMethods().PaymentMethods();
                            ViewData.Add("paymentMethods", paymentMethods);
                        }
                    }
                    else
                    {
                        ViewData["ipIsNull"] = true;
                    }

                    var countriesHash = (List <Hashtable>)localesList.Countries();
                    var languagesHash = (List <Hashtable>)localesList.Languages();

                    List <SelectListItem> countriesList = GetCountries(ref countriesHash);
                    countriesList = countriesList.OrderBy(x => x.Text).ToList();

                    List <SelectListItem> languagesList = GetLanguages(ref languagesHash);
                    languagesList = languagesList.OrderBy(x => x.Text).ToList();

                    ViewData.Add("countries", new SelectList(countriesList, "Value", "Text", locales[1]));
                    ViewData.Add("languages", new SelectList(languagesList, "Value", "Text", locales[0]));

                    if (TempData["error"] != null)
                    {
                        ViewData["error"] = TempData["error"];
                    }

                    return(View(product));
                }
                catch (Exception e)
                {
                    string mesg = GetExceptionMessage(e);

                    if (mesg == "")
                    {
                        throw e;
                    }
                    else
                    {
                        LogEntry(e.Message);
                        ViewData["error"] = mesg;
                        return(View("../products/index", db.Products.ToList()));
                    }
                }
            }
            else
            {
                throw new HttpException(404, "Sorry, Resource not available");
            }
        }
        public ActionResult Create(int productId = 0)
        {
            System.Diagnostics.Debug.WriteLine("exception is   :oolllaaaaa " );

            Product product = db.Products.Find(productId);

            if (product != null)
            {
                try
                {

                    //Exception ex2 = new Exception("this is the first exception");
                    //throw ex2;

                    PriceSetting ps = new PriceSetting(product.PriceSettingId);

                    string userIp = GetUserIP();
                    string locale = "";
                    string[] locales;

                    if (!String.IsNullOrWhiteSpace(userIp))
                    {
                        LocalForIPResponse localeResponse = ps.LocaleForIP(userIp);
                        locale = localeResponse.Locale();

                        ps.LOCALE = locale;
                        locales = locale.Split('-');

                        try
                        {
                            List<Hashtable> paymentMethods = ps.ListPaymentMethods().PaymentMethods();
                            ViewData.Add("paymentMethods", paymentMethods);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                        }

                    }
                    else
                    {
                        ViewData["ipIsNull"] = true;
                        locales = "en-".Split('-');
                    }

                    ListLocalesResponse localesList = ps.ListLocales();

                    List<SelectListItem> countriesList = null;
                    List<SelectListItem> languagesList = null;

                    GetSelectList(ref localesList, ref countriesList, true);
                    GetSelectList(ref localesList, ref languagesList, false);

                    ViewData.Add("countries", new SelectList(countriesList, "Value", "Text", locales[1]));
                    ViewData.Add("languages", new SelectList(languagesList, "Value", "Text", locales[0]));

                    if (TempData["error"] != null)
                        ViewData["error"] = TempData["error"];

                    return View(product);
                }
                catch (Exception e)
                {

                    string mesg = GetExceptionMessage(e);

                    if (mesg == "")
                        throw e;
                    else
                    {
                        LogEntry(e.Message);
                        ViewData["error"] = mesg;
                        return View("../products/index", db.Products.ToList());
                    }
                }
            }
            else
            {
                throw new HttpException(404, "Sorry, Resource not available");
            }
        }
コード例 #20
0
        public ActionResult Create(FormCollection form)
        {
            int productId       = 0;
            int paymentMethodId = 0;

            Int32.TryParse(form["productId"], out productId);

            Product product = db.Products.Find(productId);

            if (product != null)
            {
                if (Int32.TryParse(form["paymentMethod"], out paymentMethodId) && form["languagesList"] != null && form["countriesList"] != null)
                {
                    Purchase purchase = null;

                    try
                    {
                        PriceSetting ps = new PriceSetting(product.PriceSettingId);

                        string locale = form["languagesList"] + "-" + form["countriesList"];

                        ps.LOCALE            = locale;
                        ps.PAYMENT_METHOD_ID = paymentMethodId;
                        ps.PAYALOGUE_ID      = product.PayalogueId;

                        purchase = CreatePurchase(product);

                        NameValueCollection options = new NameValueCollection();
                        options.Add("purchase_id", purchase.ID.ToString());
                        PaymentResponse payment = ps.CreatePayment(options);

                        purchase.Update(payment);
                        db.SaveChanges();

                        return(Redirect("https://secure.zaypay.com" + payment.PayalogueUrl()));
                    }
                    catch (Exception e)
                    {
                        string mesg = GetExceptionMessage(e);

                        if (purchase != null)
                        {
                            RemovePurchase(ref purchase);
                        }

                        if (mesg == "")
                        {
                            throw e;
                        }
                        else
                        {
                            LogEntry(e.Message);
                            TempData["error"] = mesg;
                            return(RedirectToAction("Create", new { productId = product.ID }));
                        }
                    }
                }
                else
                {
                    TempData["error"] = "Language , Country or Payment Method is not selected properly";
                    return(RedirectToAction("Create", new { productId = product.ID }));
                }
            }
            else
            {
                throw new HttpException(404, "Sorry, Resource Not Found");
            }

            //return RedirectToAction("Details",new { id = purchase.ID});
        }