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

Marshall Bowers created

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

Change summary

crates/collab/src/api/billing.rs | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

Detailed changes

crates/collab/src/api/billing.rs 🔗

@@ -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);