From 44a9ff57e73d12abb048d4d5a7beff3c60447723 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 26 Sep 2025 09:27:50 +0500 Subject: [PATCH] common: add new subscription types --- Notesnook.API/Services/UserService.cs | 10 +- .../Enums/SubscriptionPlan.cs | 33 +++++ .../Enums/SubscriptionStatus.cs | 30 +++++ .../Enums/SubscriptionType.cs | 62 ++++----- .../Messages/CreateSubscriptionMessage.cs | 127 +++++++++--------- .../Messages/CreateSubscriptionMessageV2.cs | 69 ++++++++++ Streetwriters.Common/WampServers.cs | 1 + 7 files changed, 235 insertions(+), 97 deletions(-) create mode 100644 Streetwriters.Common/Enums/SubscriptionPlan.cs create mode 100644 Streetwriters.Common/Enums/SubscriptionStatus.cs create mode 100644 Streetwriters.Common/Messages/CreateSubscriptionMessageV2.cs diff --git a/Notesnook.API/Services/UserService.cs b/Notesnook.API/Services/UserService.cs index 671386b..f8734b8 100644 --- a/Notesnook.API/Services/UserService.cs +++ b/Notesnook.API/Services/UserService.cs @@ -77,11 +77,12 @@ namespace Notesnook.API.Services if (!Constants.IS_SELF_HOSTED) { - await WampServers.SubscriptionServer.PublishMessageAsync(SubscriptionServerTopics.CreateSubscriptionTopic, new CreateSubscriptionMessage + await WampServers.SubscriptionServer.PublishMessageAsync(SubscriptionServerTopics.CreateSubscriptionV2Topic, new CreateSubscriptionMessageV2 { AppId = ApplicationType.NOTESNOOK, Provider = SubscriptionProvider.STREETWRITERS, - Type = SubscriptionType.BASIC, + Status = SubscriptionStatus.ACTIVE, + Plan = SubscriptionPlan.FREE, UserId = response.UserId, StartTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), }); @@ -96,14 +97,15 @@ namespace Notesnook.API.Services var user = await userService.GetUserAsync(Clients.Notesnook.Id, userId) ?? throw new Exception("User not found."); - ISubscription subscription = null; + Subscription? subscription = null; if (Constants.IS_SELF_HOSTED) { subscription = new Subscription { AppId = ApplicationType.NOTESNOOK, Provider = SubscriptionProvider.STREETWRITERS, - Type = SubscriptionType.PREMIUM, + Plan = SubscriptionPlan.BELIEVER, + Status = SubscriptionStatus.ACTIVE, UserId = user.UserId, StartDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), // this date doesn't matter as the subscription is static. diff --git a/Streetwriters.Common/Enums/SubscriptionPlan.cs b/Streetwriters.Common/Enums/SubscriptionPlan.cs new file mode 100644 index 0000000..bcfd792 --- /dev/null +++ b/Streetwriters.Common/Enums/SubscriptionPlan.cs @@ -0,0 +1,33 @@ +/* +This file is part of the Notesnook Sync Server project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the Affero GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +Affero GNU General Public License for more details. + +You should have received a copy of the Affero GNU General Public License +along with this program. If not, see . +*/ + +using System; + +namespace Streetwriters.Common.Enums +{ + public enum SubscriptionPlan + { + FREE = 0, + ESSENTIAL = 1, + PRO = 2, + BELIEVER = 3, + EDUCATION = 4, + LEGACY_PRO = 5 + } +} \ No newline at end of file diff --git a/Streetwriters.Common/Enums/SubscriptionStatus.cs b/Streetwriters.Common/Enums/SubscriptionStatus.cs new file mode 100644 index 0000000..876a739 --- /dev/null +++ b/Streetwriters.Common/Enums/SubscriptionStatus.cs @@ -0,0 +1,30 @@ +/* +This file is part of the Notesnook Sync Server project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the Affero GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +Affero GNU General Public License for more details. + +You should have received a copy of the Affero GNU General Public License +along with this program. If not, see . +*/ + +namespace Streetwriters.Common.Enums +{ + public enum SubscriptionStatus + { + ACTIVE, + TRIAL, + CANCELED, + PAUSED, + EXPIRED + } +} \ No newline at end of file diff --git a/Streetwriters.Common/Enums/SubscriptionType.cs b/Streetwriters.Common/Enums/SubscriptionType.cs index b194c2c..4be1ccf 100644 --- a/Streetwriters.Common/Enums/SubscriptionType.cs +++ b/Streetwriters.Common/Enums/SubscriptionType.cs @@ -1,32 +1,32 @@ -/* -This file is part of the Notesnook Sync Server project (https://notesnook.com/) - -Copyright (C) 2023 Streetwriters (Private) Limited - -This program is free software: you can redistribute it and/or modify -it under the terms of the Affero GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -Affero GNU General Public License for more details. - -You should have received a copy of the Affero GNU General Public License -along with this program. If not, see . -*/ - -namespace Streetwriters.Common.Enums -{ - public enum SubscriptionType - { - BASIC = 0, - TRIAL = 1, - BETA = 2, - PREMIUM = 5, - PREMIUM_EXPIRED = 6, - PREMIUM_CANCELED = 7, - PREMIUM_PAUSED = 8 - } +/* +This file is part of the Notesnook Sync Server project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the Affero GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +Affero GNU General Public License for more details. + +You should have received a copy of the Affero GNU General Public License +along with this program. If not, see . +*/ + +namespace Streetwriters.Common.Enums +{ + public enum SubscriptionType + { + BASIC = 0, + TRIAL = 1, + BETA = 2, + PREMIUM = 5, + PREMIUM_EXPIRED = 6, + PREMIUM_CANCELED = 7, + PREMIUM_PAUSED = 8, + } } \ No newline at end of file diff --git a/Streetwriters.Common/Messages/CreateSubscriptionMessage.cs b/Streetwriters.Common/Messages/CreateSubscriptionMessage.cs index 890cd2f..bec8b7c 100644 --- a/Streetwriters.Common/Messages/CreateSubscriptionMessage.cs +++ b/Streetwriters.Common/Messages/CreateSubscriptionMessage.cs @@ -1,63 +1,66 @@ -/* -This file is part of the Notesnook Sync Server project (https://notesnook.com/) - -Copyright (C) 2023 Streetwriters (Private) Limited - -This program is free software: you can redistribute it and/or modify -it under the terms of the Affero GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -Affero GNU General Public License for more details. - -You should have received a copy of the Affero GNU General Public License -along with this program. If not, see . -*/ - -using System.Runtime.Serialization; -using System.Text.Json.Serialization; -using Streetwriters.Common.Enums; -using Streetwriters.Common.Interfaces; - -namespace Streetwriters.Common.Messages -{ - public class CreateSubscriptionMessage - { - [JsonPropertyName("userId")] - public string UserId { get; set; } - - [JsonPropertyName("provider")] - public SubscriptionProvider Provider { get; set; } - - [JsonPropertyName("appId")] - public ApplicationType AppId { get; set; } - - [JsonPropertyName("type")] - public SubscriptionType Type { get; set; } - - [JsonPropertyName("start")] - public long StartTime { get; set; } - - [JsonPropertyName("expiry")] - public long ExpiryTime { get; set; } - - [JsonPropertyName("orderId")] - public string OrderId { get; set; } - - [JsonPropertyName("updateURL")] - public string UpdateURL { get; set; } - - [JsonPropertyName("cancelURL")] - public string CancelURL { get; set; } - - [JsonPropertyName("subscriptionId")] - public string SubscriptionId { get; set; } - - [JsonPropertyName("productId")] - public string ProductId { get; set; } - public bool Extend { get; set; } - } +/* +This file is part of the Notesnook Sync Server project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the Affero GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +Affero GNU General Public License for more details. + +You should have received a copy of the Affero GNU General Public License +along with this program. If not, see . +*/ + +using System; +using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using Streetwriters.Common.Enums; +using Streetwriters.Common.Interfaces; + +namespace Streetwriters.Common.Messages +{ + public class CreateSubscriptionMessage + { + [JsonPropertyName("userId")] + public string UserId { get; set; } + + [JsonPropertyName("provider")] + public SubscriptionProvider Provider { get; set; } + + [JsonPropertyName("appId")] + public ApplicationType AppId { get; set; } + + [JsonPropertyName("type")] + public SubscriptionType Type { get; set; } + + [JsonPropertyName("start")] + public long StartTime { get; set; } + + [JsonPropertyName("expiry")] + public long ExpiryTime { get; set; } + + [JsonPropertyName("orderId")] + public string OrderId { get; set; } + + [JsonPropertyName("updateURL")] + public string UpdateURL { get; set; } + + [JsonPropertyName("cancelURL")] + public string CancelURL { get; set; } + + [JsonPropertyName("subscriptionId")] + public string SubscriptionId { get; set; } + + [JsonPropertyName("productId")] + public string ProductId { get; set; } + + [JsonPropertyName("extend")] + public bool Extend { get; set; } + } } \ No newline at end of file diff --git a/Streetwriters.Common/Messages/CreateSubscriptionMessageV2.cs b/Streetwriters.Common/Messages/CreateSubscriptionMessageV2.cs new file mode 100644 index 0000000..830faa9 --- /dev/null +++ b/Streetwriters.Common/Messages/CreateSubscriptionMessageV2.cs @@ -0,0 +1,69 @@ +/* +This file is part of the Notesnook Sync Server project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the Affero GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +Affero GNU General Public License for more details. + +You should have received a copy of the Affero GNU General Public License +along with this program. If not, see . +*/ + +using System; +using System.Runtime.Serialization; +using System.Text.Json.Serialization; +using Streetwriters.Common.Enums; +using Streetwriters.Common.Interfaces; + +namespace Streetwriters.Common.Messages +{ + public class CreateSubscriptionMessageV2 + { + [JsonPropertyName("userId")] + public string UserId { get; set; } + + [JsonPropertyName("provider")] + public SubscriptionProvider Provider { get; set; } + + [JsonPropertyName("appId")] + public ApplicationType AppId { get; set; } + + [JsonPropertyName("plan")] + public SubscriptionPlan Plan { get; set; } + + [JsonPropertyName("status")] + public SubscriptionStatus Status { get; set; } + + [JsonPropertyName("start")] + public long StartTime { get; set; } + + [JsonPropertyName("expiry")] + public long ExpiryTime { get; set; } + + [JsonPropertyName("orderId")] + public string OrderId { get; set; } + + [JsonPropertyName("subscriptionId")] + public string SubscriptionId { get; set; } + + [JsonPropertyName("productId")] + public string ProductId { get; set; } + + [JsonPropertyName("timestamp")] + public long Timestamp { get; set; } + + [JsonPropertyName("trialExpiry")] + public long TrialExpiryTime { get; set; } + + [JsonPropertyName("googlePurchaseToken")] + public string? GooglePurchaseToken { get; set; } + } +} \ No newline at end of file diff --git a/Streetwriters.Common/WampServers.cs b/Streetwriters.Common/WampServers.cs index e190b43..c3269b9 100644 --- a/Streetwriters.Common/WampServers.cs +++ b/Streetwriters.Common/WampServers.cs @@ -109,6 +109,7 @@ namespace Streetwriters.Common public const string UserSubscriptionServiceTopic = "co.streetwriters.subscriptions.subscriptions"; public const string CreateSubscriptionTopic = "co.streetwriters.subscriptions.create"; + public const string CreateSubscriptionV2Topic = "co.streetwriters.subscriptions.v2.create"; public const string DeleteSubscriptionTopic = "co.streetwriters.subscriptions.delete"; }