collab: Update billing migration endpoint to work for users without active subscriptions (#29792)
This PR updates the billing migration endpoint to work for users who do not have an active subscription. This will allow us to use the endpoint to migrate all users. Release Notes: - N/A
This commit is contained in:
parent
3bd7ae6e5b
commit
49a71ec3b8
1 changed files with 23 additions and 23 deletions
|
@ -624,7 +624,7 @@ struct MigrateToNewBillingBody {
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct MigrateToNewBillingResponse {
|
struct MigrateToNewBillingResponse {
|
||||||
/// The ID of the subscription that was canceled.
|
/// The ID of the subscription that was canceled.
|
||||||
canceled_subscription_id: String,
|
canceled_subscription_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn migrate_to_new_billing(
|
async fn migrate_to_new_billing(
|
||||||
|
@ -650,30 +650,29 @@ async fn migrate_to_new_billing(
|
||||||
.get_active_billing_subscriptions(HashSet::from_iter([user.id]))
|
.get_active_billing_subscriptions(HashSet::from_iter([user.id]))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let Some((_billing_customer, billing_subscription)) =
|
let canceled_subscription_id = if let Some((_billing_customer, billing_subscription)) =
|
||||||
old_billing_subscriptions_by_user.get(&user.id)
|
old_billing_subscriptions_by_user.get(&user.id)
|
||||||
else {
|
{
|
||||||
return Err(Error::http(
|
let stripe_subscription_id = billing_subscription
|
||||||
StatusCode::NOT_FOUND,
|
.stripe_subscription_id
|
||||||
"No active billing subscriptions to migrate".into(),
|
.parse::<stripe::SubscriptionId>()
|
||||||
));
|
.context("failed to parse Stripe subscription ID from database")?;
|
||||||
|
|
||||||
|
Subscription::cancel(
|
||||||
|
&stripe_client,
|
||||||
|
&stripe_subscription_id,
|
||||||
|
stripe::CancelSubscription {
|
||||||
|
invoice_now: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Some(stripe_subscription_id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let stripe_subscription_id = billing_subscription
|
|
||||||
.stripe_subscription_id
|
|
||||||
.parse::<stripe::SubscriptionId>()
|
|
||||||
.context("failed to parse Stripe subscription ID from database")?;
|
|
||||||
|
|
||||||
Subscription::cancel(
|
|
||||||
&stripe_client,
|
|
||||||
&stripe_subscription_id,
|
|
||||||
stripe::CancelSubscription {
|
|
||||||
invoice_now: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let feature_flags = app.db.list_feature_flags().await?;
|
let feature_flags = app.db.list_feature_flags().await?;
|
||||||
|
|
||||||
for feature_flag in ["new-billing", "assistant2"] {
|
for feature_flag in ["new-billing", "assistant2"] {
|
||||||
|
@ -691,7 +690,8 @@ async fn migrate_to_new_billing(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Json(MigrateToNewBillingResponse {
|
Ok(Json(MigrateToNewBillingResponse {
|
||||||
canceled_subscription_id: stripe_subscription_id.to_string(),
|
canceled_subscription_id: canceled_subscription_id
|
||||||
|
.map(|subscription_id| subscription_id.to_string()),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue