public static DataAccessResponseType UpdatePlanAllowImageEnhancements(string paymentPlanName, bool allowEnhancements) { #region Validate Input //Is this already the plans visibility? return error if true. #endregion bool sqlTransactionSucceeded = false; #region SQL Transaction //Start SQL Transaction sqlTransactionSucceeded = Sql.Statements.UpdateStatements.UpdatePlanAllowImageEnhancements(paymentPlanName, allowEnhancements); #endregion if (sqlTransactionSucceeded) { //Clear the cache and return results: PaymentPlanCaching.InvalidateAllCaches(true); return(new DataAccessResponseType { isSuccess = true }); } else { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "There was an issue updating the database." }); } }
public static DataAccessResponseType UpdatePlanMaxImages(string paymentPlanName, int newLimit) { #region Validate Input if (newLimit < 0) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "Must be a positive number." }); } #endregion bool sqlTransactionSucceeded = false; #region SQL Transaction //Start SQL Transaction sqlTransactionSucceeded = Sql.Statements.UpdateStatements.UpdateMaxImages(paymentPlanName, newLimit); #endregion if (sqlTransactionSucceeded) { //Clear the cache and return results: PaymentPlanCaching.InvalidateAllCaches(true); return(new DataAccessResponseType { isSuccess = true }); } else { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "There was an issue updating the database." }); } }
public static DataAccessResponseType DeletePaymentPlan(string paymentPlanName) { var stripeManager = new StripeManager(); var paymentPlan = GetPaymentPlan(paymentPlanName); var frequencies = GetPaymentFrequencies(); #region Validate Plan Deletion if (paymentPlanName.ToLower() == "unprovisioned") { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot delete the unprovisioned plan." }); } if (paymentPlanName.ToLower().Contains("trial") || paymentPlanName.ToLower().Contains("free")) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot delete the Free or Trial plans." }); } //Check if any accounts belong to the plan on SQL before deleting if (Sql.Statements.SelectStatements.AccountsWithPlanExists(paymentPlanName)) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot delete a plan that has accounts associated to it." }); } #endregion #region 1. Delete each plan/frequency varient on Stripe (if applicable) if (paymentPlan.MonthlyRate != 0) { //If paid account, delete each varient (only paid accounts are on Stripe) foreach (var frequency in frequencies) { if (frequency.PaymentFrequencyMonths != 0) { try { stripeManager.DeletePlan(Common.Methods.Billing.GenerateStripePlanID(paymentPlan.PaymentPlanName, frequency.IntervalCount, frequency.Interval)); } catch (Exception e) { //Log exception and email platform admins PlatformExceptionsHelper.LogExceptionAndAlertAdmins( e, "attempting to delete a payment plan on Stripe", System.Reflection.MethodBase.GetCurrentMethod() ); } } } } #endregion #region 2. Delete the plan on SQL try { var isSuccess = Sql.Statements.DeleteStatements.DeletePlan(paymentPlanName); //Clear the cache and return results: PaymentPlanCaching.InvalidateAllCaches(); return(new DataAccessResponseType { isSuccess = isSuccess }); } catch (Exception e) { //Log exception and email platform admins PlatformExceptionsHelper.LogExceptionAndAlertAdmins( e, "attempting to delete a payment plan in SQL", System.Reflection.MethodBase.GetCurrentMethod() ); return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "An error occured while attempting to delete the plan on the databse. " + e.Message, }); } #endregion }
public static DataAccessResponseType CreatePaymentPlan(PaymentPlan paymentPlan) { var response = new DataAccessResponseType(); var stripeManager = new StripeManager(); var frequencies = GetPaymentFrequencies(); #region Validate Input //Validate Plan Name var validationResponse = ValidationManager.IsValidPaymentPlanName(paymentPlan.PaymentPlanName); if (!validationResponse.isValid) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = validationResponse.validationMessage }); } if (paymentPlan.MaxCategorizationsPerSet > 80) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "Categories cannot be grouped in amounts greater than 80 per set" }); } if (paymentPlan.MaxProductsPerSet > 300) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "Products cannot be grouped in amounts greater than 300 per set" }); } if (paymentPlan.MaxProperties > 160) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 160 properties on an account" }); } if (paymentPlan.MaxValuesPerProperty > 60) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 60 values per property on an account" }); } if (paymentPlan.MaxTags > 5000) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 5000 tags on an account" }); } if (paymentPlan.MaxUsers > 300) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 300 users on an account" }); } if (paymentPlan.MaxImageGroups > 60) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 60 image groups on an account" }); } if (paymentPlan.MaxImageFormats > 240) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 240 image formats on an account" }); } if (paymentPlan.MaxImageGalleries > 30) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 30 image galleries on an account" }); } if (paymentPlan.MaxImagesPerGallery > 50) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot have more than 50 images per gallery on an account" }); } #endregion #region 1. STRIPE transaction (if applicable) if (paymentPlan.MonthlyRate != 0) { //Add to stripe first, if fails, respond with error and stop the process. foreach (PaymentFrequency frequency in frequencies) { // We ignore any payment plans that have no cost and or frequencies that are set to 0 // Stripe is only used to manage plans that have a cost associated to it above 0.0 if (frequency.PaymentFrequencyMonths != 0) { //Create the new Stripe plan ID var id = Sahara.Core.Common.Methods.Billing.GenerateStripePlanID(paymentPlan.PaymentPlanName, frequency.IntervalCount, frequency.Interval); //Check if plan exists in Stripe, return an error if it does if (stripeManager.PlanExists(id).isSuccess) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "Plan variant exists on Stripe. Operation aborted." }); } //Create the rest of the new Stripe plan var name = Sahara.Core.Common.Methods.Billing.GenerateStripePlanName(paymentPlan.PaymentPlanName, frequency.PaymentFrequencyName); var amount = Sahara.Core.Common.Methods.Billing.GenerateStripePlanAmountInCents(paymentPlan.MonthlyRate, frequency.PaymentFrequencyMonths, frequency.PriceBreak); try { stripeManager.CreatePlan( id, name, amount, frequency.Interval, frequency.IntervalCount ); } catch (Exception e) { //Log exception and email platform admins PlatformExceptionsHelper.LogExceptionAndAlertAdmins( e, "attempting to create a payment plan on Stripe", System.Reflection.MethodBase.GetCurrentMethod() ); return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "An error occurred while attempting to add a plan varient to Stripe. Operation aborted." }); } } } } else { } #endregion #region 2. SQL Transaction try { response.isSuccess = Sql.Statements.InsertStatements.InsertPaymentPlan(paymentPlan.PaymentPlanName, paymentPlan.Visible, paymentPlan.MonthlyRate, paymentPlan.MaxUsers, paymentPlan.MaxCategorizationsPerSet, paymentPlan.MaxProductsPerSet, paymentPlan.MaxProperties, paymentPlan.MaxValuesPerProperty, paymentPlan.MaxTags, paymentPlan.AllowSalesLeads, paymentPlan.MonthlySupportHours, paymentPlan.AllowLocationData, paymentPlan.AllowCustomOrdering, paymentPlan.AllowThemes, paymentPlan.AllowImageEnhancements, paymentPlan.MaxImageGroups, paymentPlan.MaxImageFormats, paymentPlan.MaxImageGalleries, paymentPlan.MaxImagesPerGallery).isSuccess; //Clear the cache and return results: PaymentPlanCaching.InvalidateAllCaches(); return(response); } catch (Exception e) { //Log exception and email platform admins PlatformExceptionsHelper.LogExceptionAndAlertAdmins( e, "attempting to insert a payment plan into SQL", System.Reflection.MethodBase.GetCurrentMethod() ); return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "Stripe transaction was successful, but there was an issue while attempting to add plan to the database. Operation aborted. " + e.Message }); } #endregion }