fix(stripe): classify never paid trial orgs#2252
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughThe PR refactors Stripe paid-invoice export filtering by introducing a ChangesStripe Never-Paid Customer Export Filtering
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
scripts/stripe_paid_invoice_export_utils.ts (1)
185-201:⚠️ Potential issue | 🟠 Major | ⚡ Quick winBroaden the positive-payment scan to catch partially paid invoices.
customerIdsWithPositivePaidInvoicesis derived fromstripe.invoices.list({ status: 'paid' }), which excludes invoices with partial payments. Per Stripe API documentation, invoices can haveamount_paid > 0while remaining inopenstatus (until fully paid and transitioning topaid). These partially paid open invoices will be missed by the current status filter, incorrectly classifying those customers asnever_paid. Collect the positive-payment set from all invoices (or at minimum open invoices), while keeping the paid-coverage logic restricted to paid subscription invoices.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/stripe_paid_invoice_export_utils.ts` around lines 185 - 201, The current scan sets invoiceListParams.status = 'paid', which misses partially paid invoices in 'open' state; remove the status filter from invoiceListParams (or explicitly include open invoices) when building invoiceListParams used by stripe.invoices.list so that the loop over stripe.invoices.list(invoiceListParams) sees invoices of all relevant statuses; keep the existing checks inside the loop (toStripeId(invoice.customer), shouldIncludeCustomer, and getInvoiceAmountPaid(invoice) > 0 that adds to customerIdsWithPositivePaidInvoices) unchanged so only invoices with amount_paid > 0 are counted, and preserve the existing paid-subscription coverage logic elsewhere that should remain restricted to fully paid invoices.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@scripts/stripe_paid_invoice_export_utils.ts`:
- Around line 185-201: The current scan sets invoiceListParams.status = 'paid',
which misses partially paid invoices in 'open' state; remove the status filter
from invoiceListParams (or explicitly include open invoices) when building
invoiceListParams used by stripe.invoices.list so that the loop over
stripe.invoices.list(invoiceListParams) sees invoices of all relevant statuses;
keep the existing checks inside the loop (toStripeId(invoice.customer),
shouldIncludeCustomer, and getInvoiceAmountPaid(invoice) > 0 that adds to
customerIdsWithPositivePaidInvoices) unchanged so only invoices with amount_paid
> 0 are counted, and preserve the existing paid-subscription coverage logic
elsewhere that should remain restricted to fully paid invoices.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d2f073c8-0a33-4e63-8e3f-fd87442d4850
📒 Files selected for processing (2)
scripts/export_stripe_six_month_org_emails.tsscripts/stripe_paid_invoice_export_utils.ts
|



Summary (AI generated)
--status=never_paidmeans org-linked Stripe customers with no positive paid invoice at all.paid,active, andcanceledexports.never_paidstatus.Motivation (AI generated)
The trial churn export should identify org users whose org never paid anything, not customers that merely lack subscription coverage while still having another positive paid invoice.
Business Impact (AI generated)
This makes the CSV reliable for trial-churn outreach and avoids mixing paid customers into the never-paid segment.
Test Plan (AI generated)
bunx eslint --no-ignore scripts/export_stripe_six_month_org_emails.ts scripts/stripe_paid_invoice_export_utils.tsbun --bun tsc --noEmit --ignoreConfig --skipLibCheck --allowImportingTsExtensions --moduleResolution bundler --module ESNext --target ESNext scripts/export_stripe_six_month_org_emails.ts scripts/stripe_paid_invoice_export_utils.tsgit diff --checkbun scripts/export_stripe_six_month_org_emails.ts --helpSummary by CodeRabbit
Bug Fixes
Chores