Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
collab: Don't create a Zed Free subscription if one already exists in Stripe (#30983)
Marshall Bowersf73c8e584153
diff --git a/crates/collab/src/stripe_billing.rs b/crates/collab/src/stripe_billing.rsindex a538adf4017..20803fa446f 100644--- a/crates/collab/src/stripe_billing.rs+++ b/crates/collab/src/stripe_billing.rs@@ -310,6 +310,32 @@ impl StripeBilling {) -> Result<stripe::Subscription> {let zed_free_price_id = self.zed_free_price_id().await?;+ let existing_subscriptions = stripe::Subscription::list(+ &self.client,+ &stripe::ListSubscriptions {+ customer: Some(customer_id.clone()),+ status: None,+ ..Default::default()+ },+ )+ .await?;++ let existing_zed_free_subscription =+ existing_subscriptions+ .data+ .into_iter()+ .find(|subscription| {+ subscription.status == SubscriptionStatus::Active+ && subscription.items.data.iter().any(|item| {+ item.price+ .as_ref()+ .map_or(false, |price| price.id == zed_free_price_id)+ })+ });+ if let Some(subscription) = existing_zed_free_subscription {+ return Ok(subscription);+ }+let mut params = stripe::CreateSubscription::new(customer_id);params.items = Some(vec![stripe::CreateSubscriptionItems {price: Some(zed_free_price_id.to_string()),