Skip to main content

djs_model/
sku.rs

1//! [SKUs](https://docs.discord.com/developers/resources/sku): the premium offerings (one-time
2//! purchases and subscriptions) an app sells.
3
4use compact_str::CompactString;
5use serde::{Deserialize, Serialize};
6
7use crate::{
8    id::{ApplicationId, SkuId},
9    macros::{int_enum, int_flags},
10};
11
12/// A [SKU](https://docs.discord.com/developers/resources/sku#sku-object): a premium offering
13/// (one-time purchase or subscription) of an app.
14///
15/// To tell user from guild subscriptions, check [`flags`](Self::flags).
16///
17/// discord.js counterpart: `SKU`.
18#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
19#[non_exhaustive]
20pub struct Sku {
21    /// The SKU's ID.
22    pub id: SkuId,
23    /// The kind of offering.
24    #[serde(rename = "type")]
25    pub kind: SkuType,
26    /// The application that sells it.
27    pub application_id: ApplicationId,
28    /// The name shown to customers.
29    pub name: CompactString,
30    /// A URL slug generated from the name.
31    pub slug: CompactString,
32    /// The SKU's flags.
33    pub flags: SkuFlags,
34}
35
36int_enum! {
37    /// The [kind of a SKU](https://docs.discord.com/developers/resources/sku#sku-object-sku-types).
38    ///
39    /// discord.js counterpart: `SKUType`.
40    pub enum SkuType: u8 {
41        /// A one-time purchase that is kept.
42        Durable = 2,
43        /// A one-time purchase that is used up.
44        Consumable = 3,
45        /// A recurring subscription.
46        Subscription = 5,
47        /// The group Discord creates for each [`Subscription`](Self::Subscription) SKU.
48        SubscriptionGroup = 6,
49    }
50}
51
52int_flags! {
53    /// [Flags of a SKU](https://docs.discord.com/developers/resources/sku#sku-object-sku-flags).
54    ///
55    /// discord.js counterpart: `SKUFlags` / `SKUFlagsBitField`.
56    pub struct SkuFlags: u64 {
57        /// The SKU can be purchased.
58        const AVAILABLE = 1 << 2;
59        /// A recurring subscription bought by a user for one guild; everyone in that guild gets
60        /// the benefits.
61        const GUILD_SUBSCRIPTION = 1 << 7;
62        /// A recurring subscription bought by a user for themselves, valid in every guild.
63        const USER_SUBSCRIPTION = 1 << 8;
64    }
65}