Пример #1
0
        public ActionResult _EnrollSmartPit(FormCollection fc)
        {
            Response.ContentType = "application/json";
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError)
            };
            try
            {
                if (!Request.IsAjaxRequest())
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                    ReturnCode.StatusMessage = "Your request is invalid.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                if (!GlobalConfig.IsSmartPitReloadEnabled)
                {
                    ReturnCode.StatusCode = (int)ReloadError.SMARTPIT_RELOAD_IS_DISABLED;
                    ReturnCode.StatusMessage = "SmartPit reloading is currently disabled.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                if (User.Identity.IsAuthenticated)
                {
                    var registDt = DateTime.Now;
                    var context = new IPTV2Entities();
                    System.Guid userId = new System.Guid(User.Identity.Name);
                    User user = context.Users.FirstOrDefault(u => u.UserId == userId);

                    Offering offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId);

                    if (user != null)
                    {
                        if (offering != null)
                        {
                            if (user.HasPendingGomsChangeCountryTransaction(offering))
                            {
                                ReturnCode.StatusCode = (int)ErrorCodes.HasPendingChangeCountryTransaction;
                                ReturnCode.StatusMessage = "We are processing your recent change in location. Please try again after a few minutes.";
                                return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                            }

                            if (user.HasExceededMaximumReloadTransactionsForTheDay(GlobalConfig.reloadTransactionMaximumThreshold, registDt))
                            {
                                ReturnCode.StatusCode = (int)ErrorCodes.MaximumTransactionsExceeded;
                                ReturnCode.StatusMessage = String.Format("You have exceeded the maximum number of transactions ({0}) allowed per day. Please try again later.", GlobalConfig.paymentTransactionMaximumThreshold);
                                return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                            }
                        }

                        if (String.Compare(user.CountryCode, GlobalConfig.JapanCountryCode, true) != 0)
                        {
                            ReturnCode.StatusCode = (int)ErrorCodes.UnauthorizedCountry;
                            ReturnCode.StatusMessage = "You are not allowed to use this feature.";
                            return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                        }

                        if (!String.IsNullOrEmpty(user.SmartPitId))
                        {
                            ReturnCode.StatusCode = (int)ErrorCodes.IsAlreadyEnrolledToSmartPit;
                            ReturnCode.StatusMessage = "You already have an enrolled SmartPit Card Number.";
                            return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                        }


                        var SmartPitCardNumber = String.IsNullOrEmpty(fc["SmartPitCardNumber"]) ? String.Empty : fc["SmartPitCardNumber"];
                        string ErrorMessage = String.Empty;
                        var service = new GomsTfcTv();
                        try
                        {
                            var response = service.EnrollSmartPit(context, user.UserId, SmartPitCardNumber);

                            if (response.IsSuccess)
                            {
                                user.SmartPitId = response.SmartPitCardNo;
                                user.SmartPitRegistrationDate = registDt;
                                if (context.SaveChanges() > 0)
                                {
                                    ReturnCode.StatusCode = (int)ErrorCodes.Success;
                                    ReturnCode.StatusMessage = String.Format("You have successfully {0} a SmartPit Card Number.", String.IsNullOrEmpty(SmartPitCardNumber) ? "generated" : "enrolled");
                                    ReturnCode.info = response.SmartPitCardNo;
                                }
                                else
                                {
                                    ReturnCode.StatusCode = (int)ErrorCodes.EntityUpdateError;
                                    ReturnCode.StatusMessage = "The system encountered an unspecified error. Please contact Customer Support.";
                                }
                            }
                            else
                            {
                                ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                                ReturnCode.StatusMessage = response.StatusMessage;
                            }
                        }
                        catch (Exception e)
                        {
                            MyUtility.LogException(e);
                            ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                            ReturnCode.StatusMessage = e.Message;
                        }
                    }
                }
                else
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.NotAuthenticated;
                    ReturnCode.StatusMessage = "Your session has expired. Please login again.";
                }
            }
            catch (Exception e)
            {
                MyUtility.LogException(e);
                ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                ReturnCode.StatusMessage = e.Message;
            }
            return Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
Пример #2
0
        public ActionResult _CreateSmartPit(FormCollection fc)
        {
            Dictionary<string, object> collection = new Dictionary<string, object>();
            ErrorCodes errorCode = ErrorCodes.UnknownError;
            string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError);
            collection = MyUtility.setError(errorCode, errorMessage);
            if (!MyUtility.isUserLoggedIn())
            {
                collection = MyUtility.setError(ErrorCodes.NotAuthenticated);
                return Content(MyUtility.buildJson(collection), "application/json");
            }

            var context = new IPTV2Entities();
            var userId = new Guid(User.Identity.Name);

            User user = context.Users.FirstOrDefault(u => u.UserId == userId);
            if (user == null)
            {
                collection = MyUtility.setError(ErrorCodes.UnknownError, "User does not exist");
                return Content(MyUtility.buildJson(collection), "application/json");
            }

            if (user.Country == null)
            {
                collection = MyUtility.setError(ErrorCodes.UnknownError, "User's country is missing.");
                return Content(MyUtility.buildJson(collection), "application/json");
            }
            if (user.Country.Code != GlobalConfig.JapanCountryCode)
            {
                collection = MyUtility.setError(ErrorCodes.UnknownError, "User is not authorized.");
                return Content(MyUtility.buildJson(collection), "application/json");
            }
            if (!String.IsNullOrEmpty(user.SmartPitId))
            {
                collection = MyUtility.setError(ErrorCodes.UnknownError, "User is already enrolled.");
                return Content(MyUtility.buildJson(collection), "application/json");
            }

            DateTime registDt = DateTime.Now;
            var smartpitcardno = String.IsNullOrEmpty(fc["SmartPitCardNumber"]) ? String.Empty : fc["SmartPitCardNumber"];

            var service = new GomsTfcTv();
            try
            {
                var response = service.EnrollSmartPit(context, userId, smartpitcardno);

                if (response.IsSuccess)
                {
                    user.SmartPitId = response.SmartPitCardNo;
                    user.SmartPitRegistrationDate = registDt;
                    if (context.SaveChanges() > 0)
                    {
                        collection = MyUtility.setError(ErrorCodes.Success, response.StatusMessage);
                        collection.Add("spcno", response.SmartPitCardNo);
                    }
                    else
                        collection = MyUtility.setError(ErrorCodes.EntityUpdateError, "Unable to process your request. Please try again later.");
                }
                else
                    collection = MyUtility.setError(ErrorCodes.EntityUpdateError, response.StatusMessage);
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                collection = MyUtility.setError(ErrorCodes.UnknownError, String.Format("{0} {1}", e.Message, e.InnerException == null ? String.Empty : e.InnerException.Message));
            }

            return Content(MyUtility.buildJson(collection), "application/json");
        }
Пример #3
0
        //[RequireHttps]
        public ActionResult _EnrollSmartPitCardNumber(FormCollection fc)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = String.Empty,
                info = "SmartPit",
                TransactionType = "Load"
            };

            string url = Url.Action("Index", "Load").ToString();
            try
            {
                DateTime registDt = DateTime.Now;
                Dictionary<string, string> tmpCollection = fc.AllKeys.ToDictionary(k => k, v => fc[v]);
                bool isMissingRequiredFields = false;

                foreach (var x in tmpCollection)
                {
                    if (String.IsNullOrEmpty(x.Value))
                    {
                        isMissingRequiredFields = true;
                        break;
                    }
                }

                if (!isMissingRequiredFields) // process form
                {
                    if (GlobalConfig.IsSmartPitReloadEnabled)
                    {
                        if (User.Identity.IsAuthenticated)
                        {
                            var context = new IPTV2Entities();
                            System.Guid userId = new System.Guid(User.Identity.Name);
                            User user = context.Users.FirstOrDefault(u => u.UserId == userId);
                            if (user != null)
                            {
                                var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId);
                                if (offering != null)
                                {
                                    if (user.HasPendingGomsChangeCountryTransaction(offering))
                                        ReturnCode.StatusMessage = "We are processing your recent change in location. Please try again after a few minutes.";
                                    else if (user.HasExceededMaximumReloadTransactionsForTheDay(GlobalConfig.reloadTransactionMaximumThreshold, registDt))
                                        ReturnCode.StatusMessage = String.Format("You have exceeded the maximum number of transactions ({0}) allowed per day. Please try again later.", GlobalConfig.reloadTransactionMaximumThreshold);
                                    else if (String.Compare(user.CountryCode, GlobalConfig.JapanCountryCode, true) != 0)
                                        ReturnCode.StatusMessage = "This payment mode is not available in your country.";
                                    else if (!String.IsNullOrEmpty(user.SmartPitId))
                                        ReturnCode.StatusMessage = "You already have enrolled a SmartPit Card Number.";
                                    else
                                    {
                                        var SmartPitCardNumber = String.IsNullOrEmpty(fc["SmartPitCardNumber"]) ? String.Empty : fc["SmartPitCardNumber"];
                                        var service = new GomsTfcTv();
                                        var response = service.EnrollSmartPit(context, user.UserId, SmartPitCardNumber);
                                        if (response.IsSuccess)
                                        {
                                            user.SmartPitId = response.SmartPitCardNo;
                                            user.SmartPitRegistrationDate = registDt;
                                            if (context.SaveChanges() > 0)
                                            {
                                                ReturnCode.StatusCode = (int)ErrorCodes.Success;
                                                ReturnCode.StatusHeader = "You have successfully enrolled!";
                                                ReturnCode.StatusMessage = String.Format("You have successfully {0} SmartPit Card Number {1}.", String.IsNullOrEmpty(SmartPitCardNumber) ? "generated" : "enrolled", response.SmartPitCardNo);
                                                ReturnCode.StatusMessage2 = "You can now start reloading your E-Wallet using your SmartPit Card Number.";
                                                TempData["ErrorMessage"] = ReturnCode;
                                                return RedirectToAction("Index", "Home"); // successful reload
                                            }
                                            else
                                                ReturnCode.StatusMessage = "The system encountered an unspecified error. Please contact Customer Support.";

                                        }
                                        else
                                        {
                                            ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                                            ReturnCode.StatusMessage = response.StatusMessage;
                                        }

                                    }
                                }
                                else
                                    ReturnCode.StatusMessage = "Service not found. Please contact support.";

                            }
                            else
                                ReturnCode.StatusMessage = "User does not exist.";
                        }
                        else
                            ReturnCode.StatusMessage = "Your session has already expired. Please login again.";
                    }
                    else
                        ReturnCode.StatusMessage = "Prepaid Card/ePIN payment is currenty disabled.";
                }
                else
                    ReturnCode.StatusMessage = "Please fill in all required fields.";

                TempData["ErrorMessage"] = ReturnCode;
                url = Request.UrlReferrer.AbsolutePath;
            }
            catch (Exception e)
            {
                MyUtility.LogException(e);
                ReturnCode.StatusMessage = e.Message;
                TempData["ErrorMessage"] = ReturnCode;
            }
            return Redirect(url);
        }