Skip to main content

app_store_server_library/models/
status.rs

1use serde::{Deserialize, Serialize};
2
3/// The status of an auto-renewable subscription.
4///
5/// [status](https://developer.apple.com/documentation/appstoreserverapi/status)
6#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)]
7#[serde(from = "i64", into = "i64")]
8pub enum Status {
9    Active,
10    Expired,
11    BillingRetry,
12    BillingGracePeriod,
13    Revoked,
14
15    /// A value the App Store sent that this version of the
16    /// library does not support, preserved as received.
17    NotSupported(i64),
18}
19
20impl Status {
21    pub fn raw_value(&self) -> i64 {
22        i64::from(self.clone())
23    }
24}
25
26impl From<i64> for Status {
27    fn from(value: i64) -> Self {
28        match value {
29            1 => Status::Active,
30            2 => Status::Expired,
31            3 => Status::BillingRetry,
32            4 => Status::BillingGracePeriod,
33            5 => Status::Revoked,
34            other => Status::NotSupported(other),
35        }
36    }
37}
38
39impl From<Status> for i64 {
40    fn from(value: Status) -> Self {
41        match value {
42            Status::Active => 1,
43            Status::Expired => 2,
44            Status::BillingRetry => 3,
45            Status::BillingGracePeriod => 4,
46            Status::Revoked => 5,
47            Status::NotSupported(other) => other,
48        }
49    }
50}