Skip to content

Commit

Permalink
collab: Anchor new subscription's billing cycle to the first of the m…
Browse files Browse the repository at this point in the history
…onth (#19367)

This PR makes it so new subscriptions will have their billing cycle
anchored to the first of the month.

When someone signs up today, they will be billed starting on the first
of next month.

Release Notes:

- N/A

Co-authored-by: Antonio <[email protected]>
Co-authored-by: Richard <[email protected]>
  • Loading branch information
3 people authored and osiewicz committed Oct 18, 2024
1 parent 267a06c commit 34d3bc8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/collab/src/stripe_billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 34d3bc8

Please sign in to comment.