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.
This commit is contained in:
Emma Alexia
2025-06-28 15:57:38 -06:00
committed by GitHub
parent cf767c7ef2
commit e2668f20b7

View File

@@ -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(