collab: Add has_overdue_invoices
to billing_customers
(#24239)
This PR adds a new `has_overdue_invoices` field to the `billing_customers` table. This will be used to statefully track whether a customer has overdue invoices, and also to reset it when the invoices are paid. We will set this field to `true` when a subscription is canceled with the reason `payment_failed`. Release Notes: - N/A
This commit is contained in:
parent
b13498a5dd
commit
aa3da35e8e
5 changed files with 27 additions and 0 deletions
|
@ -666,6 +666,27 @@ async fn handle_customer_subscription_event(
|
|||
.await?
|
||||
.ok_or_else(|| anyhow!("billing customer not found"))?;
|
||||
|
||||
let was_canceled_due_to_payment_failure = subscription.status == SubscriptionStatus::Canceled
|
||||
&& subscription
|
||||
.cancellation_details
|
||||
.as_ref()
|
||||
.and_then(|details| details.reason)
|
||||
.map_or(false, |reason| {
|
||||
reason == CancellationDetailsReason::PaymentFailed
|
||||
});
|
||||
|
||||
if was_canceled_due_to_payment_failure {
|
||||
app.db
|
||||
.update_billing_customer(
|
||||
billing_customer.id,
|
||||
&UpdateBillingCustomerParams {
|
||||
has_overdue_invoices: ActiveValue::set(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(existing_subscription) = app
|
||||
.db
|
||||
.get_billing_subscription_by_stripe_subscription_id(&subscription.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue