feat(labrinth): quarterly billing support (#3714)

This commit is contained in:
Alejandro González 2025-05-29 00:18:24 +02:00 committed by GitHub
parent f52d020a3c
commit be37f077d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -49,6 +49,7 @@ pub enum Price {
#[serde(rename_all = "kebab-case")]
pub enum PriceDuration {
Monthly,
Quarterly,
Yearly,
}
@ -56,6 +57,7 @@ impl PriceDuration {
pub fn duration(&self) -> chrono::Duration {
match self {
PriceDuration::Monthly => chrono::Duration::days(30),
PriceDuration::Quarterly => chrono::Duration::days(90),
PriceDuration::Yearly => chrono::Duration::days(365),
}
}
@ -63,19 +65,27 @@ impl PriceDuration {
pub fn from_string(string: &str) -> PriceDuration {
match string {
"monthly" => PriceDuration::Monthly,
"quarterly" => PriceDuration::Quarterly,
"yearly" => PriceDuration::Yearly,
_ => PriceDuration::Monthly,
}
}
pub fn as_str(&self) -> &'static str {
match self {
PriceDuration::Monthly => "monthly",
PriceDuration::Quarterly => "quarterly",
PriceDuration::Yearly => "yearly",
}
}
pub fn iterator() -> impl Iterator<Item = PriceDuration> {
vec![PriceDuration::Monthly, PriceDuration::Yearly].into_iter()
vec![
PriceDuration::Monthly,
PriceDuration::Quarterly,
PriceDuration::Yearly,
]
.into_iter()
}
}

View File

@ -1856,6 +1856,7 @@ pub async fn stripe_webhook(
"source": source,
"payment_interval": metadata.charge_item.subscription_interval.map(|x| match x {
PriceDuration::Monthly => 1,
PriceDuration::Quarterly => 3,
PriceDuration::Yearly => 12,
})
}))