-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement app subscriptions #111
Draft
AnotherZane
wants to merge
7
commits into
Quahu:master
Choose a base branch
from
AnotherZane:app-subscriptions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5e26c64
Implement app subscriptions
AnotherZane 3217cda
Remove unnecessary changes
AnotherZane c9b7d83
Fix docs
AnotherZane 318e6c9
Remove more unnecessary changes
AnotherZane 66a4ede
Additional rest extentsion method
AnotherZane 3f5aceb
Add query params for list entitlements endpoint
AnotherZane de766fc
Implement one-time purchase entitlement support
AnotherZane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Disqord.Core/Entities/Core/Application/Monetization/IEntitlement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using Disqord.Models; | ||
|
||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents an entitlement of a user or a guild to a premium offering. | ||
/// </summary> | ||
public interface IEntitlement: ISnowflakeEntity, IPossiblyGuildEntity, IJsonUpdatable<EntitlementJsonModel> | ||
{ | ||
/// <summary> | ||
/// Gets the ID of the SKU this entitlement offers. | ||
/// </summary> | ||
Snowflake SkuId { get; } | ||
|
||
/// <summary> | ||
/// Gets the ID of the application this entitlement belongs to. | ||
/// </summary> | ||
Snowflake ApplicationId { get; } | ||
|
||
/// <summary> | ||
/// Gets the ID of the user this entitlement is for. | ||
/// </summary> | ||
Snowflake? UserId { get; } | ||
|
||
/// <summary> | ||
/// Gets the type of this entitlement. | ||
/// </summary> | ||
EntitlementType Type { get; } | ||
|
||
/// <summary> | ||
/// Gets whether this entitlement is deleted. | ||
/// </summary> | ||
bool Deleted { get; } | ||
|
||
/// <summary> | ||
/// Gets the date from which the entitlement is valid. | ||
/// </summary> | ||
DateTimeOffset? StartsAt { get; } | ||
|
||
/// <summary> | ||
/// Gets the date from which the entitlement is no longer valid. | ||
/// </summary> | ||
DateTimeOffset? EndsAt { get; } | ||
|
||
/// <summary> | ||
/// Gets whether this entitlement has been consumed. | ||
/// </summary> | ||
bool HasBeenConsumed { get; } | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Disqord.Core/Entities/Core/Application/Monetization/ISku.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Disqord.Models; | ||
|
||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents a Discord SKU (stock-keeping unit) for premium offerings. | ||
/// </summary> | ||
public interface ISku : ISnowflakeEntity, INamableEntity, IJsonUpdatable<SkuJsonModel> | ||
{ | ||
/// <summary> | ||
/// Gets the type of this SKU. | ||
/// </summary> | ||
SkuType Type { get; } | ||
|
||
/// <summary> | ||
/// Gets the ID of the application this SKU belongs to. | ||
/// </summary> | ||
Snowflake ApplicationId { get; } | ||
|
||
/// <summary> | ||
/// Gets the system-generated URL slug of this SKU. | ||
/// </summary> | ||
string Slug { get; } | ||
|
||
/// <summary> | ||
/// Gets the flags of this SKU. | ||
/// </summary> | ||
SkuFlags Flags { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Disqord.Core/Entities/Transient/Application/Monetization/TransientEntitlement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using Disqord.Models; | ||
using Qommon; | ||
|
||
namespace Disqord; | ||
|
||
/// <inheritdoc cref="IEntitlement"/> | ||
public class TransientEntitlement : TransientClientEntity<EntitlementJsonModel>, IEntitlement | ||
{ | ||
/// <inheritdoc/> | ||
public Snowflake Id => Model.Id; | ||
|
||
/// <inheritdoc/> | ||
public Snowflake? GuildId => Model.GuildId.GetValueOrDefault(); | ||
|
||
/// <inheritdoc/> | ||
public Snowflake SkuId => Model.SkuId; | ||
|
||
/// <inheritdoc/> | ||
public Snowflake ApplicationId => Model.ApplicationId; | ||
|
||
/// <inheritdoc/> | ||
public Snowflake? UserId => Model.UserId.GetValueOrDefault(); | ||
|
||
/// <inheritdoc/> | ||
public EntitlementType Type => Model.Type; | ||
|
||
/// <inheritdoc/> | ||
public bool Deleted => Model.Deleted; | ||
|
||
/// <inheritdoc/> | ||
public DateTimeOffset? StartsAt => Model.StartsAt; | ||
|
||
/// <inheritdoc/> | ||
public DateTimeOffset? EndsAt => Model.StartsAt; | ||
|
||
/// <inheritdoc/> | ||
public bool HasBeenConsumed => Model.Consumed.GetValueOrDefault(); | ||
|
||
public TransientEntitlement(IClient client, EntitlementJsonModel model) | ||
: base(client, model) | ||
{ } | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Disqord.Core/Entities/Transient/Application/Monetization/TransientSku.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Disqord.Models; | ||
|
||
namespace Disqord; | ||
|
||
/// <inheritdoc cref="ISku"/> | ||
public class TransientSku : TransientClientEntity<SkuJsonModel>, ISku | ||
{ | ||
/// <inheritdoc/> | ||
public Snowflake Id => Model.Id; | ||
|
||
/// <inheritdoc cref="INamableEntity.Name"/> | ||
public string Name => Model.Name; | ||
|
||
/// <inheritdoc/> | ||
public SkuType Type => Model.Type; | ||
|
||
/// <inheritdoc/> | ||
public Snowflake ApplicationId => Model.ApplicationId; | ||
|
||
/// <inheritdoc/> | ||
public string Slug => Model.Slug; | ||
|
||
/// <inheritdoc/> | ||
public SkuFlags Flags => Model.Flags; | ||
|
||
public TransientSku(IClient client, SkuJsonModel model) | ||
: base(client, model) | ||
{ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents the type of the owner of an entitlement. | ||
/// </summary> | ||
public enum EntitlementOwnerType | ||
{ | ||
Guild = 1, | ||
User = 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents the type of a entitlement. | ||
/// </summary> | ||
public enum EntitlementType | ||
{ | ||
/// <summary> | ||
/// The entitlement was purchased by the user. | ||
/// </summary> | ||
Purchase = 1, | ||
|
||
/// <summary> | ||
/// The entitlement was a part of a Discord Nitro subscription. | ||
/// </summary> | ||
PremiumSubscription = 2, | ||
|
||
/// <summary> | ||
/// The entitlement was gifted by a developer. | ||
/// </summary> | ||
DeveloperGift = 3, | ||
|
||
/// <summary> | ||
/// The entitlement was purchased by a developer in application test mode. | ||
/// </summary> | ||
TestModePurchase = 4, | ||
|
||
/// <summary> | ||
/// The entitlement was granted when the SKU was free. | ||
/// </summary> | ||
FreePurchase = 5, | ||
|
||
/// <summary> | ||
/// The entitlement was gifted by another user. | ||
/// </summary> | ||
UserGift = 6, | ||
|
||
/// <summary> | ||
/// The entitlement was claimed by the user for free as a Nitro Subscriber. | ||
/// </summary> | ||
PremiumPurchase = 7, | ||
|
||
/// <summary> | ||
/// The entitlement was purchased as an app subscription. | ||
/// </summary> | ||
ApplicationSubscription = 8 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents flags for SKUs. | ||
/// </summary> | ||
[Flags] | ||
public enum SkuFlags | ||
{ | ||
/// <summary> | ||
/// The SKU is available for purchase. | ||
/// </summary> | ||
Available = 1 << 2, | ||
|
||
/// <summary> | ||
/// A recurring SKU that can be purchased for a single guild. | ||
/// Grants access to every user in the guild. | ||
/// </summary> | ||
GuildSubscription = 1 << 7, | ||
|
||
/// <summary> | ||
/// A recurring SKU that can be purchased for a user. | ||
/// Grants access to the purchasing user in every guild. | ||
/// </summary> | ||
UserSubscription = 1 << 8 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents the type of a SKU. | ||
/// </summary> | ||
public enum SkuType | ||
{ | ||
/// <summary> | ||
/// Represents a durable one-time purchase. | ||
/// </summary> | ||
Durable = 2, | ||
|
||
/// <summary> | ||
/// Represents a consumable one-time purchase. | ||
/// </summary> | ||
Consumable = 3, | ||
|
||
/// <summary> | ||
/// Represents a recurring subscription. | ||
/// </summary> | ||
Subscription = 5, | ||
|
||
/// <summary> | ||
/// Represents a system-generated group for subscriptions. | ||
/// </summary> | ||
SubscriptionGroup = 6 | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Disqord.Core/Models/Application/Monetization/EntitlementJsonModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Disqord.Serialization.Json; | ||
using Qommon; | ||
|
||
namespace Disqord.Models; | ||
|
||
public class EntitlementJsonModel : JsonModel | ||
{ | ||
[JsonProperty("id")] | ||
public Snowflake Id; | ||
|
||
[JsonProperty("type")] | ||
public EntitlementType Type; | ||
|
||
[JsonProperty("sku_id")] | ||
public Snowflake SkuId; | ||
|
||
[JsonProperty("application_id")] | ||
public Snowflake ApplicationId; | ||
|
||
[JsonProperty("user_id")] | ||
public Optional<Snowflake> UserId; | ||
|
||
[JsonProperty("deleted")] | ||
public bool Deleted; | ||
|
||
[JsonProperty("starts_at")] | ||
public DateTimeOffset? StartsAt; | ||
|
||
[JsonProperty("ends_at")] | ||
public DateTimeOffset? EndsAt; | ||
|
||
[JsonProperty("guild_id")] | ||
public Optional<Snowflake> GuildId; | ||
|
||
[JsonProperty("consumed")] | ||
public Optional<bool> Consumed; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so sure about this description, the docs aren't very clear about it.