Example #1
0
        private void UpdateRecurringBillingViaEditProfile(IPTV2Entities context, User user, string list, bool? enable)
        {
            try
            {
                DateTime registDt = DateTime.Now;
                var rb_list = list.Split(',');

                var gomsService = new GomsTfcTv();

                if (rb_list.Count() > 0)
                {
                    foreach (var item in rb_list)
                    {
                        if (!String.IsNullOrEmpty(item))
                        {
                            var name = item;
                            if (MyUtility.isUserLoggedIn())
                            {
                                bool RecurringStatus = false;
                                if (enable != null)
                                    RecurringStatus = (bool)enable;

                                int RecurringBillingId = 0;
                                try { RecurringBillingId = Convert.ToInt32(name.Substring(2)); }
                                catch (Exception e) { MyUtility.LogException(e); }

                                if (user != null)
                                {
                                    var CurrencyCode = GlobalConfig.DefaultCurrency;
                                    try { CurrencyCode = user.Country.CurrencyCode; }
                                    catch (Exception) { }
                                    string cancellation_remarks = String.Empty;
                                    string reference = String.Empty;
                                    bool serviceUpdateSuccess = false;
                                    var billing = user.RecurringBillings.FirstOrDefault(r => r.RecurringBillingId == RecurringBillingId && r.StatusId != 2);
                                    if (billing != null)
                                    {
                                        //Check first if there is a same package with recurring turned on
                                        if (user.RecurringBillings.Count(r => r.PackageId == billing.PackageId && r.StatusId == GlobalConfig.Visible && r.RecurringBillingId != billing.RecurringBillingId) > 0)
                                        {
                                            //there is same package with recurring enabled.                                            
                                        }
                                        else
                                        {
                                            if (billing is PaypalRecurringBilling)
                                            {
                                                try
                                                {
                                                    var paypalrbilling = (PaypalRecurringBilling)billing;

                                                    billing.StatusId = RecurringStatus ? 1 : 0;
                                                    billing.UpdatedOn = registDt;
                                                    if (registDt.Date > billing.NextRun && RecurringStatus)
                                                        billing.NextRun = registDt.AddDays(1).Date;
                                                    if (!RecurringStatus)
                                                    {
                                                        try
                                                        {
                                                            if (PaymentHelper.CancelPaypalRecurring(paypalrbilling.SubscriberId))
                                                            {
                                                                reference = String.Format("PayPal Payment Renewal {0} cancelled", billing.RecurringBillingId);
                                                                String.Format("{0} - PayPal Recurring Billing Id cancelled", billing.RecurringBillingId);
                                                                serviceUpdateSuccess = true;
                                                            }
                                                        }
                                                        catch (Exception) { }
                                                    }
                                                }
                                                catch (Exception) { }
                                            }
                                            else
                                            {
                                                if (RecurringStatus)
                                                {
                                                    billing.StatusId = RecurringStatus ? 1 : 0;
                                                    billing.UpdatedOn = registDt;
                                                    if (registDt.Date > billing.NextRun && RecurringStatus)
                                                        billing.NextRun = registDt.AddDays(1).Date;
                                                }
                                                else //if (!RecurringStatus)
                                                {
                                                    try
                                                    {
                                                        var result = gomsService.CancelRecurringPayment(user, billing.Product);
                                                        if (result.IsSuccess)
                                                        {
                                                            billing.StatusId = RecurringStatus ? 1 : 0;
                                                            billing.UpdatedOn = registDt;
                                                            reference = String.Format("Credit Card Payment Renewal {0} cancelled", billing.RecurringBillingId);
                                                            cancellation_remarks = String.Format("{0} - Credit Card Recurring Billing Id cancelled", billing.RecurringBillingId);
                                                            serviceUpdateSuccess = true;
                                                        }
                                                        else
                                                            throw new Exception(result.StatusMessage);
                                                    }
                                                    catch (Exception e) { MyUtility.LogException(e); }
                                                }
                                            }

                                            if (!RecurringStatus && serviceUpdateSuccess)
                                            {
                                                var transaction = new CancellationTransaction()
                                                {
                                                    Amount = 0,
                                                    Currency = CurrencyCode,
                                                    OfferingId = GlobalConfig.offeringId,
                                                    CancellationRemarks = cancellation_remarks,
                                                    OriginalTransactionId = -1,
                                                    GomsTransactionId = -1000,
                                                    Date = registDt,
                                                    Reference = reference,
                                                    StatusId = GlobalConfig.Visible
                                                };
                                                user.Transactions.Add(transaction);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
        }
Example #2
0
        public JsonResult CancelRecurring(int? pid)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = String.Empty
            };

            DateTime registDt = DateTime.Now;
            try
            {
                if (pid == null)
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                    ReturnCode.StatusMessage = "Request is not valid";
                    return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }
                if (!Request.IsAjaxRequest())
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                    ReturnCode.StatusMessage = "Request is not valid";
                    return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                if (User.Identity.IsAuthenticated)
                {
                    var context = new IPTV2Entities();
                    var userId = new Guid(User.Identity.Name);
                    var user = context.Users.FirstOrDefault(u => u.UserId == userId);
                    if (user != null)
                    {
                        var product = context.Products.FirstOrDefault(p => p.ProductId == (int)pid);
                        if (product != null)
                        {
                            if (product is SubscriptionProduct)
                            {
                                var subscription_product = (SubscriptionProduct)product;
                                var packageIds = subscription_product.ProductGroup.GetPackageIds(true);
                                var CurrencyCode = GlobalConfig.DefaultCurrency;
                                try { CurrencyCode = user.Country.CurrencyCode; }
                                catch (Exception) { }
                                var rb = context.RecurringBillings.Where(r => r.UserId == user.UserId && r.StatusId == GlobalConfig.Visible && packageIds.Contains(r.PackageId));
                                if (rb != null)
                                {
                                    if (rb.Count() > 0)
                                    {
                                        var gomsService = new GomsTfcTv();
                                        foreach (var billing in rb)
                                        {
                                            string reference = String.Empty;
                                            bool serviceUpdateSuccess = false;
                                            string cancellation_remarks = String.Empty;
                                            if (billing is PaypalRecurringBilling)
                                            {
                                                try
                                                {
                                                    var paypalrbilling = (PaypalRecurringBilling)billing;
                                                    billing.StatusId = 0;
                                                    billing.UpdatedOn = registDt;
                                                    try
                                                    {
                                                        if (PaymentHelper.CancelPaypalRecurring(paypalrbilling.SubscriberId))
                                                        {
                                                            reference = String.Format("PayPal Payment Renewal id {0} cancelled", billing.RecurringBillingId);
                                                            String.Format("{0} - PayPal Recurring Billing Id cancelled", billing.RecurringBillingId);
                                                            serviceUpdateSuccess = true;
                                                        }
                                                    }
                                                    catch (Exception) { }
                                                }
                                                catch (Exception) { }
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    var result = gomsService.CancelRecurringPayment(user, billing.Product);
                                                    if (result.IsSuccess)
                                                    {
                                                        billing.StatusId = 0;
                                                        billing.UpdatedOn = registDt;
                                                        reference = String.Format("Credit Card Payment Renewal {0} cancelled", billing.RecurringBillingId);
                                                        cancellation_remarks = String.Format("{0} - Credit Card Recurring Billing Id cancelled", billing.RecurringBillingId);
                                                        serviceUpdateSuccess = true;
                                                    }
                                                    else
                                                    {
                                                        ReturnCode.StatusMessage = result.StatusMessage;
                                                        throw new Exception(result.StatusMessage);
                                                    }

                                                }
                                                catch (Exception) { }
                                            }

                                            //serviceUpdateSuccess = true;
                                            if (serviceUpdateSuccess)
                                            {
                                                var transaction = new CancellationTransaction()
                                                {
                                                    Amount = 0,
                                                    Currency = CurrencyCode,
                                                    OfferingId = GlobalConfig.offeringId,
                                                    CancellationRemarks = cancellation_remarks,
                                                    OriginalTransactionId = -1,
                                                    GomsTransactionId = -1000,
                                                    Date = registDt,
                                                    Reference = reference,
                                                    StatusId = GlobalConfig.Visible
                                                };
                                                user.Transactions.Add(transaction);
                                            }
                                        }

                                        if (context.SaveChanges() > 0)
                                        {
                                            ReturnCode.StatusCode = (int)ErrorCodes.Success;
                                            ReturnCode.StatusMessage = "We have disabled all your automatic payment renewal.";
                                        }
                                    }
                                }
                            }

                        }
                    }
                }
                else
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.NotAuthenticated;
                    ReturnCode.StatusMessage = "User is not authenticated";
                    return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
Example #3
0
        private void UpdateRecurringBillingViaEditProfile2(IPTV2Entities context, User user, string list, bool? enable)
        {
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    var rb_list = list.Replace("rs", "");
                    var billingIds = MyUtility.StringToIntList(rb_list);
                    DateTime registDt = DateTime.Now;
                    if (billingIds.Count() > 0)
                    {
                        var gomsService = new GomsTfcTv();
                        var recurring_billings = user.RecurringBillings.Where(r => billingIds.Contains(r.RecurringBillingId) && r.StatusId != 2);
                        if (recurring_billings != null)
                        {
                            if (recurring_billings.Count() > 0)
                            {
                                bool RecurringStatus = false;
                                if (enable != null)
                                    RecurringStatus = (bool)enable;

                                var CurrencyCode = GlobalConfig.DefaultCurrency;
                                try { CurrencyCode = user.Country.CurrencyCode; }
                                catch (Exception) { }

                                foreach (var billing in recurring_billings)
                                {
                                    string cancellation_remarks = String.Empty;
                                    string reference = String.Empty;
                                    bool serviceUpdateSuccess = false;

                                    if (user.RecurringBillings.Count(r => r.PackageId == billing.PackageId && r.StatusId == GlobalConfig.Visible && r.RecurringBillingId != billing.RecurringBillingId) > 0)
                                    {
                                        //there is same package with recurring enabled.                                            
                                    }
                                    else
                                    {
                                        if (billing is PaypalRecurringBilling)
                                        {
                                            try
                                            {
                                                var paypalrbilling = (PaypalRecurringBilling)billing;

                                                billing.StatusId = RecurringStatus ? 1 : 0;
                                                billing.UpdatedOn = registDt;
                                                if (registDt.Date > billing.NextRun && RecurringStatus)
                                                    billing.NextRun = registDt.AddDays(1).Date;
                                                if (!RecurringStatus)
                                                {
                                                    try
                                                    {
                                                        if (PaymentHelper.CancelPaypalRecurring(paypalrbilling.SubscriberId))
                                                        {
                                                            reference = String.Format("PayPal billing id {0} cancelled", billing.RecurringBillingId);
                                                            cancellation_remarks = String.Format("{0} - PayPal Recurring Billing Id cancelled", billing.RecurringBillingId);
                                                            serviceUpdateSuccess = true;
                                                        }
                                                    }
                                                    catch (Exception) { }
                                                }
                                            }
                                            catch (Exception) { }
                                        }
                                        else
                                        {
                                            billing.StatusId = RecurringStatus ? 1 : 0;
                                            billing.UpdatedOn = registDt;
                                            if (registDt.Date > billing.NextRun && RecurringStatus)
                                                billing.NextRun = registDt.AddDays(1).Date;

                                            if (!RecurringStatus)
                                            {
                                                try
                                                {
                                                    var result = gomsService.CancelRecurringPayment(user, billing.Product);
                                                    if (result.IsSuccess)
                                                    {
                                                        reference = String.Format("Credit Card billing id {0} cancelled", billing.RecurringBillingId);
                                                        cancellation_remarks = String.Format("{0} - Credit Card Recurring Billing Id cancelled", billing.RecurringBillingId);
                                                        serviceUpdateSuccess = true;
                                                    }
                                                    else
                                                        throw new Exception(result.StatusMessage);
                                                }
                                                catch (Exception e) { MyUtility.LogException(e); }
                                            }
                                        }

                                        if (!RecurringStatus && serviceUpdateSuccess)
                                        {
                                            var transaction = new CancellationTransaction()
                                            {
                                                Amount = 0,
                                                Currency = CurrencyCode,
                                                OfferingId = GlobalConfig.offeringId,
                                                CancellationRemarks = cancellation_remarks,
                                                OriginalTransactionId = -1,
                                                GomsTransactionId = -1000,
                                                Date = registDt,
                                                Reference = reference,
                                                StatusId = GlobalConfig.Visible
                                            };
                                            user.Transactions.Add(transaction);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
        }
Example #4
0
        public static bool CancelPaypalRecurringOnTFCtv(string subscr_id)
        {
            try
            {
                var registDt = DateTime.Now;
                var context = new IPTV2Entities();
                var paypalRecurring = context.RecurringBillings.Where(r => r is PaypalRecurringBilling);
                if (paypalRecurring != null)
                {
                    if (paypalRecurring.Count() > 0)
                    {
                        var recurring = paypalRecurring.ToList().FirstOrDefault(r => String.Compare(((PaypalRecurringBilling)r).SubscriberId, subscr_id, true) == 0);
                        if (recurring != null)
                        {
                            if (recurring.StatusId == GlobalConfig.Visible)
                            {
                                try
                                {
                                    var user = context.Users.FirstOrDefault(u => u.UserId == recurring.UserId);
                                    if (user != null)
                                    {
                                        var reference = String.Format("PayPal billing id {0} cancelled", recurring.RecurringBillingId);
                                        var cancellation_remarks = String.Format("{0} - PayPal Recurring Billing Id cancelled", recurring.RecurringBillingId);
                                        var transaction = new CancellationTransaction()
                                        {
                                            Amount = 0,
                                            Currency = user.Country.CurrencyCode,
                                            OfferingId = GlobalConfig.offeringId,
                                            CancellationRemarks = cancellation_remarks,
                                            OriginalTransactionId = -1,
                                            GomsTransactionId = -1000,
                                            Date = registDt,
                                            Reference = reference,
                                            StatusId = GlobalConfig.Visible
                                        };
                                        user.Transactions.Add(transaction);
                                    }
                                    recurring.StatusId = 0;
                                    recurring.UpdatedOn = registDt;
                                    return context.SaveChanges() > 0;
                                }
                                catch (Exception)
                                {
                                    recurring.StatusId = 0;
                                    recurring.UpdatedOn = registDt;
                                    return context.SaveChanges() > 0;
                                }
                            }
                            else if (recurring.StatusId == 0)
                            {
                                recurring.UpdatedOn = registDt;
                                return context.SaveChanges() > 0;
                            }
                        }
                    }

                }

            }
            catch (Exception e) { MyUtility.LogException(e); }
            return false;
        }
Example #5
0
        public TFCtvResponse UnassociateTVEverywhere(ReqUnassociateTVEverywhere req)
        {
            TFCtvResponse resp = null;
            DateTime registDt = DateTime.Now;
            string ip = ConfigurationManager.AppSettings["IpWhiteList"];
            string[] IpAddresses = ip.Split(';');
            bool isWhitelisted = IpAddresses.Contains(HttpContext.Current.Request.UserHostAddress);
            if (!isWhitelisted)
            {
                resp = new TFCtvResponse() { Code = -3001, Message = "Ip address is unauthorized." }; return resp;
            }

            if (!HttpContext.Current.Request.IsLocal)
            {
                //Check SoapHeader
                if (Credentials.Username.ToLower() != SoapHeaderUsername || Credentials.Password != SoapHeaderPassword)
                { resp = new TFCtvResponse() { Code = -3002, Message = "Call is unauthorized." }; return resp; }
            }

            if (req == null)
                resp = new TFCtvResponse() { Code = -3003, Message = "Request parameter is empty." };
            else
            {
                if (req.GomsCustomerId == null || req.GomsTransactionDate == null || req.GomsTransactionId == null)
                {
                    resp = new TFCtvResponse() { Code = -3004, Message = "Missing required fields." };
                    return resp;
                }

                var context = new IPTV2Entities();
                if (isProduction)
                    context.Database.Connection.ConnectionString = IPTV2EntitiesAzureConnectionString;


                var user = context.Users.FirstOrDefault(u => u.GomsCustomerId == req.GomsCustomerId);
                if (user == null)
                {
                    resp = new TFCtvResponse() { Code = -1001, Message = "User does not exist." };
                    return resp;
                }

                if (user.Country == null)
                {
                    resp = new TFCtvResponse() { Code = -1002, Message = "User country is not valid." };
                    return resp;
                }
                //else // Do we need to check for Japan/US only?
                //{
                //    var countries = TVECountryWhitelist.Split(',');
                //    if (!countries.Contains(user.Country.Code))
                //    {
                //        resp = new TFCtvResponse() { Code = -1002, Message = "User country is not valid." };
                //        return resp;
                //    }
                //}

                var product = context.Products.FirstOrDefault(p => p.GomsProductId == req.GomsProductId && p.GomsProductQuantity == req.GomsProductQuantity);
                if (product == null)
                {
                    resp = new TFCtvResponse() { Code = -1007, Message = "GOMS Product does not exist." };
                    return resp;
                }

                if (user.IsTVEverywhere == null)
                {
                    resp = new TFCtvResponse() { Code = -1003, Message = "User is not TFC.tv Everywhere associated." };
                    return resp;
                }
                else
                {
                    if (user.IsTVEverywhere == false)
                    {
                        resp = new TFCtvResponse() { Code = -1003, Message = "User is not TFC.tv Everywhere associated." };
                        return resp;
                    }
                }

                //if (user.Transactions.Count(t => t.GomsTransactionId == req.GomsTransactionId) > 0)
                //{
                //    resp = new TFCtvResponse() { Code = -1006, Message = "Transaction already exists in TFC.tv." };
                //    return resp;
                //}


                if (user != null)
                {

                    var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId);
                    if (productPackage == null)
                    {
                        resp = new TFCtvResponse() { Code = -1006, Message = "TFC.tv package does not exist." };
                        return resp;
                    }

                    var entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == productPackage.Package.PackageId);
                    if (entitlement != null)
                        entitlement.EndDate = (DateTime)req.GomsTransactionDate;

                    //user.LastUpdated = registDt;
                    user.LastUpdated = (DateTime)req.GomsTransactionDate;
                    user.IsTVEverywhere = false; // Set to false

                    string CurrencyCode = DefaultCurrencyCode;
                    Country country = context.Countries.FirstOrDefault(c => c.Code == user.CountryCode);
                    if (country != null)
                    {
                        Currency currency = context.Currencies.FirstOrDefault(c => c.Code == country.CurrencyCode);
                        if (currency != null) CurrencyCode = currency.Code;
                    }

                    var transaction = user.Transactions.LastOrDefault(t => t.GetType() != typeof(TfcEverywhereTransaction) && t.GomsTransactionId == req.GomsTransactionId);
                    if (transaction == null)
                    {
                        resp = new TFCtvResponse() { Code = -1004, Message = "TFC.tv Everywhere transaction not found." };
                        return resp;
                    }
                    var cancellation = new CancellationTransaction()
                    {
                        CancellationRemarks = req.Reference,
                        GomsTransactionId = -1000,
                        GomsTransactionDate = req.GomsTransactionDate,
                        OriginalTransactionId = transaction.TransactionId,
                        StatusId = 1,
                        OfferingId = offeringId,
                        Date = (DateTime)req.GomsTransactionDate,
                        Amount = 0,
                        Currency = CurrencyCode,
                        Reference = req.Reference
                    };

                    user.Transactions.Add(cancellation);
                }

                try
                {
                    if (context.SaveChanges() > 0)
                        resp = new TFCtvResponse() { Code = 0, Message = String.Format("Successfully unassociated TFC.tv Everywhere from GomsCustomerId {0}.", req.GomsCustomerId) };
                    else
                        resp = new TFCtvResponse() { Code = -1005, Message = "Unable to unassociate TFC.tv Everywhere." };
                }
                catch (Exception e)
                {
                    resp = new TFCtvResponse() { Code = -3000, Message = e.InnerException.Message };
                }

            }
            return resp;
        }
Example #6
0
        public ActionResult iteUnlinkAccount(FormCollection fc) //int idType, string iteId, string tfctvUserId
        {
            ITEResponseError iteRespErr = ITEResponseError.UNKNOWN_ERROR;
            var iteResp = new ITEResponse()
            {
                StatusCode = (int)ITEResponseError.UNKNOWN_ERROR,
                Message = MyUtility.getITEError(iteRespErr)
            };

            try
            {
                try
                {
                    var requestingIp = Request.GetUserHostAddressFromCloudflare();
                    var whiteListedIp = GlobalConfig.ITEWhitelistedIp.Split(',');
                    if (!whiteListedIp.Contains(requestingIp))
                    {
                        iteRespErr = ITEResponseError.IP_NOT_ALLOWED;
                        iteResp.Message = String.Format("{0},{1},{2},{3},{4}", (int)iteRespErr, iteRespErr.ToString(), String.Empty, String.Empty, String.Empty);
                        return this.Content(iteResp.Message, "plain/text");
                    }
                }
                catch (Exception) { }

                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
                {
                    int idType = Convert.ToInt32(fc["idType"]);
                    string iteId = fc["iteId"];
                    string tfctvUserId = fc["tfctvUserId"];

                    var registDt = DateTime.Now;
                    var context = new IPTV2Entities();
                    var user = context.Users.FirstOrDefault(u => u.UserId == new Guid(tfctvUserId));
                    if (user != null)
                    {
                        var iteDetail = user.ITEDetail;
                        if (String.Compare(iteDetail.ITEId, iteId, true) == 0)
                        {
                            //Create Cancellation Transaction
                            CancellationTransaction cancellation = new CancellationTransaction()
                            {
                                CancellationRemarks = "Unlink IT&E account",
                                GomsTransactionId = -1000,
                                GomsTransactionDate = registDt,
                                OriginalTransactionId = 0,
                                StatusId = 1,
                                OfferingId = GlobalConfig.offeringId,
                                Date = registDt,
                                Amount = 0,
                                Currency = user.Country.CurrencyCode,
                                Reference = String.Format("UNLINK IT&E ({0})", user.ITEDetail.ITEId)
                            };

                            user.Transactions.Add(cancellation);
                            context.ITEDetails.Remove(iteDetail);

                            if (context.SaveChanges() > 0)
                            {
                                iteRespErr = ITEResponseError.SUCCESS;
                                iteResp.StatusCode = (int)iteRespErr;
                                iteResp.Message = "You have unlink your IT&E account from TFC.tv";
                                iteResp.Message = String.Format("{0},{1},{2},{3},{4}", iteResp.StatusCode, iteRespErr.ToString(), String.Empty, String.Empty, String.Empty);
                                return this.Content(iteResp.Message, "plain/text");
                            }
                            else
                                iteRespErr = ITEResponseError.UNABLE_TO_COMMIT;
                        }
                        else
                            iteRespErr = ITEResponseError.ITEID_DO_NOT_MATCH;
                    }
                    else
                        iteRespErr = ITEResponseError.USER_NOT_FOUND;
                }
                else
                    iteRespErr = ITEResponseError.MISSING_PARAMETERS;

                iteResp.StatusCode = (int)iteRespErr;
                //iteResp.Message = MyUtility.getITEError(iteRespErr);
                iteResp.Message = String.Format("{0},{1},{2},{3}", iteResp.StatusCode, iteRespErr.ToString(), String.Empty, String.Empty);
            }
            catch (Exception e) { MyUtility.LogException(e); iteRespErr = ITEResponseError.UNKNOWN_ERROR; }
            //return this.Json(iteResp, JsonRequestBehavior.AllowGet);
            return this.Content(iteResp.Message, "plain/text");
        }
Example #7
0
        public ActionResult iteDeactivate(FormCollection fc) //int idType, string iteId, string tfctvUserId, string packageType, DateTime deactivationDate, string reason
        {
            ITEResponseError iteRespErr = ITEResponseError.UNKNOWN_ERROR;
            var iteResp = new ITEResponse()
            {
                StatusCode = (int)ITEResponseError.UNKNOWN_ERROR,
                Message = MyUtility.getITEError(iteRespErr)
            };
            try
            {
                try
                {
                    var requestingIp = Request.GetUserHostAddressFromCloudflare();
                    var whiteListedIp = GlobalConfig.ITEWhitelistedIp.Split(',');
                    if (!whiteListedIp.Contains(requestingIp))
                    {
                        iteRespErr = ITEResponseError.IP_NOT_ALLOWED;
                        iteResp.Message = String.Format("{0},{1},{2},{3},{4}", (int)iteRespErr, iteRespErr.ToString(), String.Empty, String.Empty, String.Empty);
                        return this.Content(iteResp.Message, "plain/text");
                    }
                }
                catch (Exception) { }

                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
                {
                    int idType = Convert.ToInt32(fc["idType"]);
                    string iteId = fc["iteId"];
                    string tfctvUserId = fc["tfctvUserId"];
                    string packageType = fc["packageType"];
                    DateTime deactivationDate = Convert.ToDateTime(fc["deactivationDate"]);
                    string reason = fc["reason"];

                    var registDt = System.DateTime.Now;
                    IPTV2Entities context = new IPTV2Entities();
                    ITEDetail iteUser = context.ITEDetails.FirstOrDefault(i => String.Compare(i.ITEId, iteId) == 0 && String.Compare(i.UserId.ToString(), tfctvUserId) == 0);
                    //check if iteuser exists
                    if (iteUser != null)
                    {
                        int packageId = ContextHelper.GetPackageFromProductId((int)ITEPackageType.LITEPACKAGE);
                        var user = context.Users.FirstOrDefault(u => u.UserId == new Guid(tfctvUserId));
                        var iteEntitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == packageId);
                        int latestITEEntitlementReqId = (int)iteEntitlement.LatestEntitlementRequestId;
                        var purchaseItem = context.PurchaseItems.FirstOrDefault(p => p.EntitlementRequestId == latestITEEntitlementReqId);
                        var iteTransaction = iteUser.User.Transactions.FirstOrDefault(t => t is WalletPaymentTransaction && ((WalletPaymentTransaction)t).PurchaseId == purchaseItem.PurchaseId);

                        //check user has free entitlement
                        if (iteEntitlement != null)
                        {
                            iteEntitlement.EndDate = deactivationDate;
                            var cancellation = new CancellationTransaction()
                            {
                                CancellationRemarks = reason,
                                GomsTransactionId = -1000,
                                GomsTransactionDate = registDt,
                                OriginalTransactionId = iteTransaction != null ? iteTransaction.TransactionId : 0,
                                StatusId = 1,
                                OfferingId = GlobalConfig.offeringId,
                                Date = registDt,
                                Amount = 0,
                                Currency = purchaseItem.Currency,
                                Reference = String.Format("DEACTIVATE IT&E ({0})", user.ITEDetail.ITEId)
                            };
                            user.Transactions.Add(cancellation);
                            if (context.SaveChanges() > 0)
                            {
                                iteRespErr = ITEResponseError.SUCCESS;
                                iteResp.StatusCode = (int)ITEResponseError.SUCCESS;
                                //iteResp.Message = String.Format(MyUtility.getITEError(ITEResponseError.SUCCESS), ITEPackageType.LITEPACKAGE.ToString(), deactivationDate.ToShortDateString());
                                iteResp.Message = String.Format("{0},{1},{2},{3},{4}", iteResp.StatusCode, iteRespErr.ToString(), ITEPackageType.LITEPACKAGE.ToString(), iteEntitlement.EndDate.ToShortDateString(), user.UserId.ToString());
                                return this.Content(iteResp.Message, "plain/text");
                            }
                        }
                        else
                            iteRespErr = ITEResponseError.ACCOUNTANI_NOT_FOUND;
                    }
                    else
                        iteRespErr = ITEResponseError.ACCOUNTANI_NOT_FOUND;
                }
                else
                    iteRespErr = ITEResponseError.MISSING_PARAMETERS;

                iteResp.StatusCode = (int)iteRespErr;
                //iteResp.Message = MyUtility.getITEError(iteRespErr);
                iteResp.Message = String.Format("{0},{1},{2},{3},{4}", iteResp.StatusCode, iteRespErr.ToString(), String.Empty, String.Empty, String.Empty);
            }
            catch (Exception e) { MyUtility.LogException(e); iteRespErr = ITEResponseError.UNKNOWN_ERROR; }
            //return this.Json(iteResp, JsonRequestBehavior.AllowGet);
            return this.Content(iteResp.Message, "plain/text");
        }