collab: Add support for launching a general-purpose billing portal session (#28785)

This PR adds a new `ManageSubscriptionIntent` that allows uses to launch
a general-purpose billing portal session to manage their subscription.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-04-15 12:40:22 -04:00 committed by GitHub
parent 05fc9ee396
commit b6cce1ed91
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -313,6 +313,10 @@ async fn create_billing_subscription(
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename_all = "snake_case")]
enum ManageSubscriptionIntent {
/// The user intends to manage their subscription.
///
/// This will open the Stripe billing portal without putting the user in a specific flow.
ManageSubscription,
/// The user intends to cancel their subscription.
Cancel,
/// The user intends to stop the cancellation of their subscription.
@ -400,7 +404,8 @@ async fn manage_billing_subscription(
}
let flow = match body.intent {
ManageSubscriptionIntent::Cancel => CreateBillingPortalSessionFlowData {
ManageSubscriptionIntent::ManageSubscription => None,
ManageSubscriptionIntent::Cancel => Some(CreateBillingPortalSessionFlowData {
type_: CreateBillingPortalSessionFlowDataType::SubscriptionCancel,
after_completion: Some(CreateBillingPortalSessionFlowDataAfterCompletion {
type_: stripe::CreateBillingPortalSessionFlowDataAfterCompletionType::Redirect,
@ -416,12 +421,12 @@ async fn manage_billing_subscription(
},
),
..Default::default()
},
}),
ManageSubscriptionIntent::StopCancellation => unreachable!(),
};
let mut params = CreateBillingPortalSession::new(customer_id);
params.flow_data = Some(flow);
params.flow_data = flow;
let return_url = format!("{}/account", app.config.zed_dot_dev_url());
params.return_url = Some(&return_url);