diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index 2f4200fd2e..91cb330252 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -36,7 +36,7 @@ use magic_crypt::MagicCryptTrait; #[cfg(feature = "enterprise")] use stripe::CustomerId; #[cfg(feature = "enterprise")] -use chrono::{TimeZone, Datelike}; +use chrono::{TimeZone, Datelike, Timelike}; use uuid::Uuid; use windmill_audit::{audit_log, ActionKind}; use windmill_common::db::UserDB; @@ -424,22 +424,25 @@ async fn stripe_checkout( _ => params.customer_email = Some(&authed.email), } + let now = Utc::now(); params.subscription_data = Some(stripe::CreateCheckoutSessionSubscriptionData { metadata: { let mut map = std::collections::HashMap::new(); map.insert("workspace_id".to_string(), w_id.clone()); Some(map) }, - billing_cycle_anchor: Some({ - // first of the next month (and possibly next year) at noon UTC - let now = Utc::now(); - let date = if now.month() == 12 { - Utc.with_ymd_and_hms(now.year() + 1, 1, 1, 12, 0, 0).single().unwrap() - } else { - Utc.with_ymd_and_hms(now.year(), now.month() + 1, 1, 12, 0, 0).single().unwrap() - }; - date.timestamp() - }), + billing_cycle_anchor: if now.day() == 1 && now.hour() < 12 { + // no need to prorate so close to the billing cycle renew date + None + } else { + // first of the next month (and possibly next year) at noon UTC + let date = if now.month() == 12 { + Utc.with_ymd_and_hms(now.year() + 1, 1, 1, 12, 0, 0).single().unwrap() + } else { + Utc.with_ymd_and_hms(now.year(), now.month() + 1, 1, 12, 0, 0).single().unwrap() + }; + Some(date.timestamp()) + }, ..Default::default() }); diff --git a/frontend/src/lib/components/settings/PremiumInfo.svelte b/frontend/src/lib/components/settings/PremiumInfo.svelte index 38da3a67ab..af6f6995b1 100644 --- a/frontend/src/lib/components/settings/PremiumInfo.svelte +++ b/frontend/src/lib/components/settings/PremiumInfo.svelte @@ -100,7 +100,7 @@ {#if plan}