Skip to content

Commit e527273

Browse files
authored
Merge pull request #93 from Sovereign-Engineering/primary-funding
Add flag for primary funding method.
2 parents db1c315 + 2ead9a0 commit e527273

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/cmd/account/info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn test_account_info_json() {
2525
"subscription": null,
2626
"apple_subscription": null,
2727
"google_subscription": null,
28+
"primary_funding": "top_up",
2829
"monero_pending_payments": [{
2930
"id": "asdas",
3031
"status": "confirming"

src/types.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ pub struct AccountInfo {
7575
#[serde(default)]
7676
pub google_subscription: Option<GoogleSubscriptionInfo>,
7777
pub monero_pending_payments: Vec<MoneroPaymentInProgress>,
78+
79+
/// The most relevant funding method for the account.
80+
///
81+
/// This is not specifically defined and the policy may change over time as payment methods and implementations change. However it is the go-to field for what funding method should be highlighted in any sort of interface that doesn't list them all.
82+
///
83+
/// Invariants:
84+
/// - If the account is active this will point at an active method.
85+
/// - If this is `None` the account has never been funded or hasn't been funded recently.
86+
pub primary_funding: Option<FundingMethod>,
87+
7888
pub stripe_subscription: Option<StripeSubscriptionInfo>,
7989
#[cfg(feature = "server")]
8090
pub subscription: Option<StripeSubscriptionInfo>,
@@ -97,6 +107,44 @@ pub struct AccountInfo {
97107
pub auto_renews: Option<i64>,
98108
}
99109

110+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
111+
#[serde(rename_all = "snake_case")]
112+
pub enum FundingMethod {
113+
AppleSubscription,
114+
GoogleSubscription,
115+
StripeSubscription,
116+
TopUp,
117+
118+
/// The client doesn't understand the funding method. Never emitted.
119+
#[serde(other)]
120+
Unknown,
121+
}
122+
123+
#[test]
124+
fn test_funding_method() {
125+
assert_eq!(serde_json::to_string(&FundingMethod::TopUp).unwrap(), r#""top_up""#,);
126+
127+
assert_eq!(
128+
serde_json::from_str::<FundingMethod>(
129+
r#"
130+
"top_up"
131+
"#
132+
)
133+
.unwrap(),
134+
FundingMethod::TopUp,
135+
);
136+
137+
assert_eq!(
138+
serde_json::from_str::<FundingMethod>(
139+
r#"
140+
"snail_mail"
141+
"#
142+
)
143+
.unwrap(),
144+
FundingMethod::Unknown,
145+
);
146+
}
147+
100148
#[derive(Clone, Debug, Deserialize, Serialize)]
101149
pub struct TopUp {
102150
pub active: bool,

0 commit comments

Comments
 (0)