diff --git a/PlotLine/Models/SubscriptionModels.cs b/PlotLine/Models/SubscriptionModels.cs index ba9ba45..d7f976b 100644 --- a/PlotLine/Models/SubscriptionModels.cs +++ b/PlotLine/Models/SubscriptionModels.cs @@ -20,6 +20,9 @@ public sealed class SubscriptionLevel public string? StripeAnnualPriceId { get; set; } public bool RequiresStripeSubscription { get; set; } public string? BillingInterval { get; set; } + public int? MonthlyPricePence { get; set; } + public int? AnnualPricePence { get; set; } + public string CurrencyCode { get; set; } = "GBP"; } public class UserSubscription @@ -60,6 +63,9 @@ public sealed class UserSubscriptionDetail : UserSubscription public int MaxCollaborators { get; set; } public bool SubscriptionLevelIsActive { get; set; } public int SortOrder { get; set; } + public int? MonthlyPricePence { get; set; } + public int? AnnualPricePence { get; set; } + public string CurrencyCode { get; set; } = "GBP"; } public sealed class SubscriptionLimitResult diff --git a/PlotLine/Sql/051_SubscriptionLevelDisplayPricing.sql b/PlotLine/Sql/051_SubscriptionLevelDisplayPricing.sql new file mode 100644 index 0000000..b49f472 --- /dev/null +++ b/PlotLine/Sql/051_SubscriptionLevelDisplayPricing.sql @@ -0,0 +1,112 @@ +SET ANSI_NULLS ON; +GO +SET QUOTED_IDENTIFIER ON; +GO + +IF NOT EXISTS (SELECT 1 FROM sys.columns WHERE object_id = OBJECT_ID(N'dbo.SubscriptionLevel') AND name = N'MonthlyPricePence') + ALTER TABLE dbo.SubscriptionLevel ADD MonthlyPricePence int NULL; +GO + +IF NOT EXISTS (SELECT 1 FROM sys.columns WHERE object_id = OBJECT_ID(N'dbo.SubscriptionLevel') AND name = N'AnnualPricePence') + ALTER TABLE dbo.SubscriptionLevel ADD AnnualPricePence int NULL; +GO + +IF NOT EXISTS (SELECT 1 FROM sys.columns WHERE object_id = OBJECT_ID(N'dbo.SubscriptionLevel') AND name = N'CurrencyCode') + ALTER TABLE dbo.SubscriptionLevel ADD CurrencyCode nvarchar(3) NOT NULL CONSTRAINT DF_SubscriptionLevel_CurrencyCode DEFAULT N'GBP'; +GO + +UPDATE dbo.SubscriptionLevel +SET MonthlyPricePence = CASE Name + WHEN N'DraftDesk' THEN NULL + WHEN N'WritingRoom' THEN 499 + WHEN N'StoryForge' THEN 799 + WHEN N'AuthorStudio' THEN 1299 + ELSE MonthlyPricePence + END, + AnnualPricePence = CASE Name + WHEN N'DraftDesk' THEN NULL + WHEN N'WritingRoom' THEN 4999 + WHEN N'StoryForge' THEN 7999 + WHEN N'AuthorStudio' THEN 12999 + ELSE AnnualPricePence + END, + CurrencyCode = N'GBP', + ModifiedDateUTC = SYSUTCDATETIME() +WHERE Name IN (N'DraftDesk', N'WritingRoom', N'StoryForge', N'AuthorStudio'); +GO + +CREATE OR ALTER PROCEDURE dbo.SubscriptionLevel_ListActive +AS +BEGIN + SET NOCOUNT ON; + + SELECT SubscriptionLevelID, Name, DisplayName, Description, MaxBooks, MaxChaptersPerBook, + MaxScenesPerBook, MaxCharactersPerProject, MaxStorageMB, MaxCollaborators, IsActive, + SortOrder, CreatedDateUTC, ModifiedDateUTC, StripeMonthlyPriceId, StripeAnnualPriceId, + RequiresStripeSubscription, MonthlyPricePence, AnnualPricePence, CurrencyCode + FROM dbo.SubscriptionLevel + WHERE IsActive = 1 + ORDER BY SortOrder, DisplayName; +END; +GO + +CREATE OR ALTER PROCEDURE dbo.SubscriptionLevel_Get + @SubscriptionLevelID int +AS +BEGIN + SET NOCOUNT ON; + + SELECT SubscriptionLevelID, Name, DisplayName, Description, MaxBooks, MaxChaptersPerBook, + MaxScenesPerBook, MaxCharactersPerProject, MaxStorageMB, MaxCollaborators, IsActive, + SortOrder, CreatedDateUTC, ModifiedDateUTC, StripeMonthlyPriceId, StripeAnnualPriceId, + RequiresStripeSubscription, MonthlyPricePence, AnnualPricePence, CurrencyCode + FROM dbo.SubscriptionLevel + WHERE SubscriptionLevelID = @SubscriptionLevelID; +END; +GO + +CREATE OR ALTER PROCEDURE dbo.SubscriptionLevel_GetByStripePrice + @StripePriceId nvarchar(100) +AS +BEGIN + SET NOCOUNT ON; + + SELECT SubscriptionLevelID, Name, DisplayName, Description, MaxBooks, MaxChaptersPerBook, + MaxScenesPerBook, MaxCharactersPerProject, MaxStorageMB, MaxCollaborators, IsActive, + SortOrder, CreatedDateUTC, ModifiedDateUTC, StripeMonthlyPriceId, StripeAnnualPriceId, + RequiresStripeSubscription, MonthlyPricePence, AnnualPricePence, CurrencyCode, + CASE + WHEN StripeMonthlyPriceId = @StripePriceId THEN N'Monthly' + WHEN StripeAnnualPriceId = @StripePriceId THEN N'Annual' + ELSE NULL + END AS BillingInterval + FROM dbo.SubscriptionLevel + WHERE IsActive = 1 + AND RequiresStripeSubscription = 1 + AND (StripeMonthlyPriceId = @StripePriceId OR StripeAnnualPriceId = @StripePriceId); +END; +GO + +CREATE OR ALTER PROCEDURE dbo.UserSubscription_GetCurrent + @UserID int +AS +BEGIN + SET NOCOUNT ON; + + SELECT us.UserSubscriptionID, us.UserID, us.SubscriptionLevelID, us.StartDateUTC, us.EndDateUTC, + us.IsActive, us.IsTrial, us.TrialExpiryDateUTC, us.CreatedDateUTC, us.ModifiedDateUTC, + us.StripeCustomerId, us.StripeSubscriptionId, us.StripePriceId, us.BillingInterval, us.StripeStatus, + us.CurrentPeriodStartUTC, us.CurrentPeriodEndUTC, us.CancelAtPeriodEnd, us.CancelledDateUTC, + us.LastPaymentFailureDateUTC, us.LastStripeEventId, + sl.Name, sl.DisplayName, sl.Description, sl.MaxBooks, sl.MaxChaptersPerBook, + sl.MaxScenesPerBook, sl.MaxCharactersPerProject, sl.MaxStorageMB, sl.MaxCollaborators, + sl.IsActive AS SubscriptionLevelIsActive, sl.SortOrder, sl.StripeMonthlyPriceId, + sl.StripeAnnualPriceId, sl.RequiresStripeSubscription, sl.MonthlyPricePence, + sl.AnnualPricePence, sl.CurrencyCode + FROM dbo.UserSubscription us + INNER JOIN dbo.SubscriptionLevel sl ON sl.SubscriptionLevelID = us.SubscriptionLevelID + WHERE us.UserID = @UserID + AND us.IsActive = 1 + AND (us.EndDateUTC IS NULL OR us.EndDateUTC > SYSUTCDATETIME()); +END; +GO diff --git a/PlotLine/Views/ManageAccount/Subscription.cshtml b/PlotLine/Views/ManageAccount/Subscription.cshtml index 2d42895..a7e26d3 100644 --- a/PlotLine/Views/ManageAccount/Subscription.cshtml +++ b/PlotLine/Views/ManageAccount/Subscription.cshtml @@ -158,6 +158,29 @@
@(isCurrent ? "Current plan" : "Available plan")
@(string.IsNullOrWhiteSpace(level.Description) ? "No description available." : level.Description)
+ @if (!level.RequiresStripeSubscription) + { +Free / trial / application managed
+ } + else + { +Monthly
+@FormatMoney(level.MonthlyPricePence.Value, level.CurrencyCode)
+Annual
+@FormatMoney(level.AnnualPricePence.Value, level.CurrencyCode)
+