Skip to content

Conversation

@jshearer
Copy link
Contributor

@jshearer jshearer commented Sep 5, 2025

Description:

  • Only skip invoices with NoDataMoved or NoFullPipeline if the customer also does not have a payment method on file. If a customer had billable usage, but then deleted all of their captures or materializations, they wouldn't have gotten an invoice prior to this change. If they have a payment method on file, we can and should bill for this legitimate usage.
  • Fix bug where invoices would get skipped if they didn't have an associated Stripe customer in the database
  • Use pre-aggregated catalog_stats_monthly table with exact tenant matching for improved query performance
  • Pre-fetch tenant trial start date from db instead of issuing another query per tenant to fetch it. This dramatically speeds things up
  • Filter manual invoices by date_start to only include those beginning within the target month
  • Enable auto_advance=true during invoice finalization, allowing Stripe to handle automatic charging and retries
  • Manual invoices for the billing period are now correctly identified and included by fetching all manual invoices and performing date filtering clientside. Stripe's API doesn't support date filters in this case :(

@jshearer jshearer marked this pull request as ready for review September 5, 2025 19:19
tracing::warn!(
?has_payment_method,
stripe_payment_method = real_default_payment_method.is_some(),
"Inconsistent payment method state"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: does this log in practice?

Copy link
Contributor Author

@jshearer jshearer Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Our stripe capture sometimes doesn't keep up, or something. I haven't looked too deeply into it. It didn't log at all this most recent time running billing, but previously it logged quite a lot.

@jshearer jshearer self-assigned this Dec 1, 2025
…e with `auto_advance`. Also add `--fix_auto_advance`, and detect+send `manual` invoices for the target month as well
@jshearer jshearer force-pushed the stripe/invoice_gen_faster branch from 5f3055c to ece937c Compare December 1, 2025 19:25
@jshearer jshearer force-pushed the stripe/invoice_gen_faster branch from ece937c to 87d38e7 Compare December 1, 2025 19:30
@jshearer jshearer requested a review from jgraettinger December 2, 2025 17:56
@jshearer
Copy link
Contributor Author

jshearer commented Dec 9, 2025

@jgraettinger ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants