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:
parent
0dc0701967
commit
eea6cfb383
1 changed files with 24 additions and 4 deletions
|
@ -449,6 +449,29 @@ async fn manage_billing_subscription(
|
||||||
let stripe_subscription =
|
let stripe_subscription =
|
||||||
Subscription::retrieve(&stripe_client, &subscription_id, &[]).await?;
|
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
|
let subscription_item_to_update = stripe_subscription
|
||||||
.items
|
.items
|
||||||
.data
|
.data
|
||||||
|
@ -456,10 +479,7 @@ async fn manage_billing_subscription(
|
||||||
.find_map(|item| {
|
.find_map(|item| {
|
||||||
let price = item.price.as_ref()?;
|
let price = item.price.as_ref()?;
|
||||||
|
|
||||||
if price.id == zed_free_price_id
|
if price.id == zed_free_price_id {
|
||||||
|| (price.id == zed_pro_price_id
|
|
||||||
&& stripe_subscription.status == SubscriptionStatus::Trialing)
|
|
||||||
{
|
|
||||||
Some(item.id.clone())
|
Some(item.id.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue