Skip to content

Payments bulldozer txn rework#1315

Merged
nams1570 merged 110 commits intodevfrom
payments-bulldozer-txn-rework
Apr 17, 2026
Merged

Payments bulldozer txn rework#1315
nams1570 merged 110 commits intodevfrom
payments-bulldozer-txn-rework

Conversation

@nams1570
Copy link
Copy Markdown
Collaborator

@nams1570 nams1570 commented Apr 9, 2026

Object of this PR

This PR is NOT a monolithic series of fixes for the payments suite + a complete rework. Its aims were
a) introducing and robustly testing the bulldozer db system
b) reworking the payments underlying architecture to use bulldozer for correctness and scalability
c) Achieving parity with the old payments system excepting a few changes like ensuring correctness of the ledger algo
There may still be some work to do with handling refunds, decoupling the concepts of purchases from that of products, and some other things.

Ledger Algorithm

This has been tuned and fixed. Item removals i.e negative item quantity changes will apply to the soonest expiring item grant i.e positive item quantity change. This is what is best for the user. Item grants can also expire, and when they expire we obviate whatever is left of their original capacity (meaning after all the removals that were applied to it). Our ledger algo is applied via Bulldozer, so automatic re-computation is handled when a new grant/ removal is inserted in the middle of the existing ones.

Things we got rid of

  • No more automatic support for default products. You can use $0 plan provisions to accomplish the same effect but it's manual
  • Negative item quantity changes (i.e item removals) no longer can have expiries
  • verify-data-integrity's payments checks. We have per table verify data integrity checks to guard against loss of data, but the overarching script needs some work. Its old implementation was buggy.

Summary by CodeRabbit

  • New Features

    • Enhanced payment processing pipeline with improved data consistency and state management.
    • Advanced refund handling with comprehensive transaction tracking.
    • Better tracking and management of customer item quantities and owned products.
    • Improved subscription lifecycle management including period-end handling.
  • Bug Fixes

    • Fixed payment data integrity verification.
    • Improved handling of edge cases in refund scenarios.
  • Chores

    • Updated cSpell configuration with additional words.
    • Expanded developer documentation for linting workflows.

Graceful handling of old include by default products. Though we dont support it anymore someone may query txns with it.
After the txn table rework this will probably not matter.
@nams1570
Copy link
Copy Markdown
Collaborator Author

@greptileai refresh summary

Comment thread apps/backend/src/lib/payments/schema/phase-1/events.ts
@nams1570
Copy link
Copy Markdown
Collaborator Author

@greptileai refresh summary

Old subscriptions may not have canceledAt, and old callers may still be expecting null for inline products
This is temporary, we defer fixing up verify data integrity payments to the future
Its better to manage this outside prisma, it gives us more flexibility
@nams1570 nams1570 enabled auto-merge (squash) April 17, 2026 21:18
@nams1570 nams1570 merged commit 1de8a17 into dev Apr 17, 2026
34 checks passed
@nams1570 nams1570 deleted the payments-bulldozer-txn-rework branch April 17, 2026 22:11
@promptless
Copy link
Copy Markdown
Contributor

promptless Bot commented Apr 17, 2026

Promptless prepared a documentation update related to this change.

Triggered by PR #1315

Documented item grants and expiration behavior in payments, including the ledger algorithm that consumes credits from soonest-expiring grants first, plus a changelog entry.

Review: Document payments ledger behavior

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.

5 participants