collab: Upgrade from Zed Pro trial to Zed Pro by ending trial period early (#29052)

This PR adjusts the upgrade from a Zed Pro trial to Zed Pro to do so by
ending the trial period early.

This will transition the subscription to `active` and bill the user
without needing to send them through a Stripe Checkout flow.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-04-18 11:29:22 -04:00 committed by GitHub
parent 0dc0701967
commit eea6cfb383
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -449,6 +449,29 @@ async fn manage_billing_subscription(
let stripe_subscription =
Subscription::retrieve(&stripe_client, &subscription_id, &[]).await?;
let is_on_zed_pro_trial = stripe_subscription.status == SubscriptionStatus::Trialing
&& stripe_subscription.items.data.iter().any(|item| {
item.price
.as_ref()
.map_or(false, |price| price.id == zed_pro_price_id)
});
if is_on_zed_pro_trial {
// If the user is already on a Zed Pro trial and wants to upgrade to Pro, we just need to end their trial early.
Subscription::update(
&stripe_client,
&stripe_subscription.id,
stripe::UpdateSubscription {
trial_end: Some(stripe::Scheduled::now()),
..Default::default()
},
)
.await?;
return Ok(Json(ManageBillingSubscriptionResponse {
billing_portal_session_url: None,
}));
}
let subscription_item_to_update = stripe_subscription
.items
.data
@ -456,10 +479,7 @@ async fn manage_billing_subscription(
.find_map(|item| {
let price = item.price.as_ref()?;
if price.id == zed_free_price_id
|| (price.id == zed_pro_price_id
&& stripe_subscription.status == SubscriptionStatus::Trialing)
{
if price.id == zed_free_price_id {
Some(item.id.clone())
} else {
None