Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

collab: Anchor new subscription's billing cycle to the first of the month (#19367)

Marshall Bowers17f2929b4c40
diff --git a/crates/collab/src/stripe_billing.rs b/crates/collab/src/stripe_billing.rs
index f7cce28a3ad..126db988a1e 100644
--- a/crates/collab/src/stripe_billing.rs
+++ b/crates/collab/src/stripe_billing.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
use crate::{llm, Cents, Result};
use anyhow::Context;
-use chrono::Utc;
+use chrono::{Datelike, Utc};
use collections::HashMap;
use serde::{Deserialize, Serialize};
use tokio::sync::RwLock;
@@ -349,10 +349,20 @@ impl StripeBilling {
model: &StripeModel,
success_url: &str,
) -> Result<String> {
+ let first_of_next_month = Utc::now()
+ .checked_add_months(chrono::Months::new(1))
+ .unwrap()
+ .with_day(1)
+ .unwrap();
+
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.subscription_data = Some(stripe::CreateCheckoutSessionSubscriptionData {
+ billing_cycle_anchor: Some(first_of_next_month.timestamp()),
+ ..Default::default()
+ });
params.line_items = Some(
[
&model.input_tokens_price.id,