From e2668f20b75d205d9c71c0c5cdc547961bf0982e Mon Sep 17 00:00:00 2001 From: Emma Alexia Date: Sat, 28 Jun 2025 15:57:38 -0600 Subject: [PATCH] Give free upgrades when billing period is near its end (#3851) Some users elect to try to perform their upgrade immediately before their subscription renews. However, we throw an error whenever the proration charge is under 30 cents because we lose more money on fees than we gain by charging the customer. This PR changes charges so that the user's server will simply be provided a free upgrade instead of requiring them to wait until after their next renewal. --- apps/labrinth/src/routes/internal/billing.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/apps/labrinth/src/routes/internal/billing.rs b/apps/labrinth/src/routes/internal/billing.rs index c4a6f9f28..a5fcbc176 100644 --- a/apps/labrinth/src/routes/internal/billing.rs +++ b/apps/labrinth/src/routes/internal/billing.rs @@ -457,20 +457,16 @@ pub async fn edit_subscription( ) })?; - // Plan downgrade, update future charge - if current_amount > amount { + // First branch: Plan downgrade, update future charge + // Second branch: For small transactions (under 30 cents), we make a loss on the + // proration due to fees. In these situations, just give it to them for free, because + // their next charge will be in a day or two anyway. + if current_amount > amount || proration < 30 { open_charge.price_id = product_price.id; open_charge.amount = amount as i64; None } else { - // For small transactions (under 30 cents), we make a loss on the proration due to fees - if proration < 30 { - return Err(ApiError::InvalidInput( - "Proration is too small!".to_string(), - )); - } - let charge_id = generate_charge_id(&mut transaction).await?; let customer_id = get_or_create_customer(