collab: Add GET /billing/subscriptions
endpoint (#15516)
This PR adds a new `GET /billing/subscriptions` endpoint to collab for retrieving the subscriptions to display on the account settings page. Release Notes: - N/A
This commit is contained in:
parent
a08e020e32
commit
2b019ff9e2
2 changed files with 73 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
use crate::db::{BillingCustomerId, BillingSubscriptionId};
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::Serialize;
|
||||
|
||||
/// A billing subscription.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel)]
|
||||
|
@ -34,8 +35,11 @@ impl ActiveModelBehavior for ActiveModel {}
|
|||
/// The status of a Stripe subscription.
|
||||
///
|
||||
/// [Stripe docs](https://docs.stripe.com/api/subscriptions/object#subscription_object-status)
|
||||
#[derive(Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum, Default, Hash)]
|
||||
#[derive(
|
||||
Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum, Default, Hash, Serialize,
|
||||
)]
|
||||
#[sea_orm(rs_type = "String", db_type = "String(None)")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum StripeSubscriptionStatus {
|
||||
#[default]
|
||||
#[sea_orm(string_value = "incomplete")]
|
||||
|
@ -55,3 +59,16 @@ pub enum StripeSubscriptionStatus {
|
|||
#[sea_orm(string_value = "paused")]
|
||||
Paused,
|
||||
}
|
||||
|
||||
impl StripeSubscriptionStatus {
|
||||
pub fn is_cancelable(&self) -> bool {
|
||||
match self {
|
||||
Self::Trialing | Self::Active | Self::PastDue => true,
|
||||
Self::Incomplete
|
||||
| Self::IncompleteExpired
|
||||
| Self::Canceled
|
||||
| Self::Unpaid
|
||||
| Self::Paused => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue