Skip to content

feat(payouts): implement settlement reconciliation and payout statements (#245) - #253

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Prompt-Hash-Stellar:mainfrom
s6pa1rta3n-lab:fix-issue-245
Draft

feat(payouts): implement settlement reconciliation and payout statements (#245)#253
s6pa1rta3n-lab wants to merge 1 commit into
Prompt-Hash-Stellar:mainfrom
s6pa1rta3n-lab:fix-issue-245

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Summary

Closes #245.

This PR implements comprehensive settlement reconciliation and creator payout statements for PromptHash, resolving all requirements outlined in #245.

Key Changes

  • Balancing Reconciliation Math: Implemented formula netSettlementAmount = grossAmount - platformFeeAmount - refundAmount + previousBalanceCarryover with 500 bps (5.00%) platform fee calculation and 7 decimal place Stellar stroop precision.
  • Carryover & Deficit Lifecycle: Managed negative balance carryovers (closingBalanceCarryover = netSettlementAmount when negative, payableAmount = 0) propagated into subsequent billing periods.
  • Refunds vs. Clawbacks: Differentiated same-period refunds from prior-period settlement clawbacks.
  • Multi-Format Export: Implemented RFC-4180 CSV export (summary metadata header block + itemized transaction ledger table with CRLF endings and quote escaping) and structured JSON export.
  • Express API Endpoints:
    • GET /api/payouts/statements/:walletAddress: List statements or calculate on-the-fly preview reconciliation for custom date ranges.
    • GET /api/payouts/statements/:walletAddress/:statementId: Fetch single statement details with line items.
    • GET /api/payouts/statements/:walletAddress/:statementId/export?format=csv|json: Download statement file.
    • POST /api/payouts/statements/generate: Generate and persist statement record.
    • PATCH /api/payouts/statements/:statementId/status: Update settlement status (pending, settled with payoutTxHash, failed with failureReason).
  • Creator UI Component (PayoutStatementsCard): Integrated into /profile/payouts (PayoutSettingsPage) and the profile Created inventory tab, displaying summary metrics, status badges, carryover notices, date range filters, RFC-4180 CSV / JSON download buttons, and an itemized transaction ledger.
  • Documentation: Added comprehensive docs in docs/payout-statements.md and updated docs/api-reference.md.
  • Test Coverage: Added 18 unit and integration tests in server/src/tests/payoutStatement.test.ts and component test in src/components/profile/PayoutStatementsCard.test.tsx. All 22 backend test suites (210 tests) and 44 frontend test suites (336 tests) pass with 0 errors.

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

…nts (Prompt-Hash-Stellar#245)

- Implement creator payout statement model with balancing formula: gross - fees (5%) - refunds + carryover = net
- Add support for partial-period filtering, prior-period refund clawbacks, and negative carryover propagation
- Add RFC-4180 CSV export with summary metadata block and itemized transaction ledger
- Add structured JSON export
- Add API endpoints for statement previews, exports, generation, and status lifecycle updates
- Mount /api/payouts and /api/reconciliation routers in Express server
- Add PayoutStatementsCard frontend component to PayoutSettingsPage and profile created tab
- Add full unit/integration test coverage across server reconciliation and frontend components
- Add comprehensive documentation in docs/payout-statements.md
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.

Prompt seller payout statements need exact fee, refund, and settlement reconciliation

1 participant