collab: Add support for subscribing to Zed Pro trials (#28812)

This PR adds support for subscribing to Zed Pro trials (and then
upgrading from a trial to Zed Pro).

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-04-15 16:49:16 -04:00 committed by GitHub
parent 5619a3e618
commit dad6067e18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 143 additions and 42 deletions

View file

@ -1,16 +1,16 @@
use std::sync::Arc;
use crate::{Cents, Result, llm};
use anyhow::{Context as _, anyhow};
use anyhow::Context as _;
use chrono::{Datelike, Utc};
use collections::HashMap;
use serde::{Deserialize, Serialize};
use stripe::PriceId;
use tokio::sync::RwLock;
pub struct StripeBilling {
state: RwLock<StripeBillingState>,
client: Arc<stripe::Client>,
zed_pro_price_id: Option<String>,
}
#[derive(Default)]
@ -32,11 +32,10 @@ struct StripeBillingPrice {
}
impl StripeBilling {
pub fn new(client: Arc<stripe::Client>, zed_pro_price_id: Option<String>) -> Self {
pub fn new(client: Arc<stripe::Client>) -> Self {
Self {
client,
state: RwLock::default(),
zed_pro_price_id,
}
}
@ -385,23 +384,19 @@ impl StripeBilling {
Ok(session.url.context("no checkout session URL")?)
}
pub async fn checkout_with_zed_pro(
pub async fn checkout_with_price(
&self,
price_id: PriceId,
customer_id: stripe::CustomerId,
github_login: &str,
success_url: &str,
) -> Result<String> {
let zed_pro_price_id = self
.zed_pro_price_id
.as_ref()
.ok_or_else(|| anyhow!("Zed Pro price ID not set"))?;
let mut params = stripe::CreateCheckoutSession::new();
params.mode = Some(stripe::CheckoutSessionMode::Subscription);
params.customer = Some(customer_id);
params.client_reference_id = Some(github_login);
params.line_items = Some(vec![stripe::CreateCheckoutSessionLineItems {
price: Some(zed_pro_price_id.clone()),
price: Some(price_id.to_string()),
quantity: Some(1),
..Default::default()
}]);