Skip to content

feat: implement real-time rent payment tracker (#16)#68

Merged
elizabetheonoja-art merged 2 commits intoLeaseFlow-Protocol:mainfrom
chigozirim007:feature/rent-payment-tracker
Mar 25, 2026
Merged

feat: implement real-time rent payment tracker (#16)#68
elizabetheonoja-art merged 2 commits intoLeaseFlow-Protocol:mainfrom
chigozirim007:feature/rent-payment-tracker

Conversation

@chigozirim007
Copy link
Copy Markdown

Summary

  • Horizon polling service (RentPaymentTrackerService) monitors the LeaseFlow contract account for incoming payment, path_payment_strict_send, and path_payment_strict_receive operations
  • Cursor-based pagination using Horizon paging_token + order=asc — each poll only fetches new operations, not the same 200 records repeatedly
  • Idempotent recording via horizon_op_id unique constraint — safe to re-run with no duplicate records
  • Auto lease matching — when a payment's sender Stellar account matches an active lease's tenant_account_id, the lease payment_status and last_payment_at are updated automatically
  • Cron scheduler (PaymentTrackerJob) starts at server boot, configurable via PAYMENT_TRACKER_CRON env var (default: every minute)
  • 3 new API endpoints:
    • GET /api/leases/:leaseId/payments — full payment history
    • GET /api/leases/:leaseId/payment-status — current status + last payment timestamp
    • GET /api/tenants/:tenantAccountId/payments — all payments for a tenant Stellar account
  • Bug fix: getLeaseById was not selecting payment_status, last_payment_at, or tenant_account_id columns — /payment-status would have returned null for all payment fields
  • DB migration 002_add_payment_history.sql adds the payment_history table and extends leases with payment tracking columns
  • 12 tests covering poll logic, idempotency, lease matching, unmatched payments, and all AppDatabase payment methods

Test plan

  • Run node node_modules/jest/bin/jest.js tests/rentPaymentTracker.test.js --forceExit — all 12 tests pass
  • Start server and verify GET /api/leases/:leaseId/payment-status returns payment_status and last_payment_at fields correctly
  • Confirm PaymentTrackerJob logs appear on boot: [PaymentTracker] Scheduled payment polling
  • Verify polling only fetches new Horizon operations after the first run (cursor working)

Closes #16

- Add RentPaymentTrackerService that polls Stellar Horizon for incoming
  payments to the LeaseFlow contract account
- Use cursor-based pagination (paging_token + order=asc) so each poll
  only fetches genuinely new operations instead of re-scanning the same
  200 records on every run
- Record every detected payment in a new payment_history table with full
  deduplication via horizon_op_id unique constraint
- Auto-update lease payment_status and last_payment_at when a payment is
  matched to an active lease by tenant Stellar account
- Add PaymentTrackerJob cron scheduler (default: every minute, override
  via PAYMENT_TRACKER_CRON env var) started at server boot
- Expose three new API endpoints via paymentRoutes:
    GET /api/leases/:leaseId/payments
    GET /api/leases/:leaseId/payment-status
    GET /api/tenants/:tenantAccountId/payments
- Fix getLeaseById to include payment_status, last_payment_at and
  tenant_account_id columns (were missing, causing /payment-status to
  return null for all payment fields)
- Add migration 002_add_payment_history.sql for the new schema columns
- Add 12 unit/integration tests covering poll logic, idempotency, lease
  matching, and all AppDatabase payment methods
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@chigozirim007 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@elizabetheonoja-art elizabetheonoja-art merged commit a406dec into LeaseFlow-Protocol:main Mar 25, 2026
1 check failed
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.

#16 Implement Real-Time_Rent_Payment_Tracker (Mercury/Horizon)

3 participants