collab: Only subscribe to Zed Free if there isn't an existing active subscription (#30967)

Marshall Bowers created

This PR adds a sanity check to ensure that we only subscribe the user to
Zed Free if they don't already have an active subscription.

Release Notes:

- N/A

Change summary

crates/collab/src/api/billing.rs | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

Detailed changes

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

@@ -1183,14 +1183,20 @@ async fn sync_subscription(
         if subscription.status == SubscriptionStatus::Canceled
             || subscription.status == SubscriptionStatus::Paused
         {
-            let stripe_customer_id = billing_customer
-                .stripe_customer_id
-                .parse::<stripe::CustomerId>()
-                .context("failed to parse Stripe customer ID from database")?;
-
-            stripe_billing
-                .subscribe_to_zed_free(stripe_customer_id)
+            let already_has_active_billing_subscription = app
+                .db
+                .has_active_billing_subscription(billing_customer.user_id)
                 .await?;
+            if !already_has_active_billing_subscription {
+                let stripe_customer_id = billing_customer
+                    .stripe_customer_id
+                    .parse::<stripe::CustomerId>()
+                    .context("failed to parse Stripe customer ID from database")?;
+
+                stripe_billing
+                    .subscribe_to_zed_free(stripe_customer_id)
+                    .await?;
+            }
         }
     }