1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! [Subscriptions](https://docs.discord.com/developers/resources/subscription): a user's
//! recurring payment for one of an app's subscription [SKUs](crate::sku).
use compact_str::CompactString;
use serde::{Deserialize, Serialize};
use crate::{
id::{EntitlementId, SkuId, SubscriptionId, UserId},
macros::int_enum,
util::Timestamp,
};
/// A [subscription](https://docs.discord.com/developers/resources/subscription#subscription-object).
///
/// Use the [`Entitlement`](crate::entitlement::Entitlement)s it grants to decide access;
/// the subscription only describes the billing period.
///
/// discord.js counterpart: `Subscription`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Subscription {
/// The subscription's ID.
pub id: SubscriptionId,
/// The subscribed user.
pub user_id: UserId,
/// The SKUs subscribed to.
pub sku_ids: Vec<SkuId>,
/// The entitlements granted by the subscription.
pub entitlement_ids: Vec<EntitlementId>,
/// The SKUs the user will be subscribed to at renewal (`None` if unchanged).
#[serde(default)]
pub renewal_sku_ids: Option<Vec<SkuId>>,
/// The start of the current period.
pub current_period_start: Timestamp,
/// The end of the current period.
pub current_period_end: Timestamp,
/// The subscription's status.
pub status: SubscriptionStatus,
/// When the subscription was canceled.
#[serde(default)]
pub canceled_at: Option<Timestamp>,
/// The ISO 3166-1 alpha-2 country code of the payment source (only with a private
/// `OAuth2` scope).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub country: Option<CompactString>,
}
int_enum! {
/// The [status of a subscription](https://docs.discord.com/developers/resources/subscription#subscription-statuses).
///
/// discord.js counterpart: `SubscriptionStatus`.
pub enum SubscriptionStatus: u8 {
/// Active and scheduled to renew.
Active = 0,
/// Inactive and not being charged.
Inactive = 1,
/// Active but will not renew.
Ending = 2,
}
}