Skip to main content

artifacts/models/
subscription_schema.rs

1use crate::models;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
5#[cfg_attr(feature = "specta", derive(specta::Type))]
6pub struct SubscriptionSchema {
7    /// Subscription plan (monthly, annual, or prepaid).
8    #[serde(rename = "plan")]
9    pub plan: models::SubscriptionPlan,
10    /// How the subscription was purchased. Mixed means both gems and member tokens were used.
11    #[serde(rename = "purchase_source")]
12    pub purchase_source: PurchaseSource,
13    /// Subscription status (active, cancelled, past_due, expired).
14    #[serde(rename = "status")]
15    pub status: String,
16    /// Start of the current billing period.
17    #[serde(rename = "current_period_start")]
18    pub current_period_start: String,
19    /// End of the current billing period.
20    #[serde(rename = "current_period_end")]
21    pub current_period_end: String,
22    /// When the subscription was created.
23    #[serde(rename = "created_at")]
24    pub created_at: String,
25    /// When the subscription was cancelled.
26    #[serde(rename = "cancelled_at", skip_serializing_if = "Option::is_none")]
27    pub cancelled_at: Option<String>,
28}
29
30impl SubscriptionSchema {
31    pub fn new(
32        plan: models::SubscriptionPlan,
33        purchase_source: PurchaseSource,
34        status: String,
35        current_period_start: String,
36        current_period_end: String,
37        created_at: String,
38    ) -> SubscriptionSchema {
39        SubscriptionSchema {
40            plan,
41            purchase_source,
42            status,
43            current_period_start,
44            current_period_end,
45            created_at,
46            cancelled_at: None,
47        }
48    }
49}
50/// How the subscription was purchased. Mixed means both gems and member tokens were used.
51#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
52#[cfg_attr(feature = "specta", derive(specta::Type))]
53#[derive(Default)]
54pub enum PurchaseSource {
55    #[serde(rename = "stripe")]
56    #[default]
57    Stripe,
58    #[serde(rename = "gems")]
59    Gems,
60    #[serde(rename = "member_token")]
61    MemberToken,
62    #[serde(rename = "mixed")]
63    Mixed,
64}