Skip to content

fix(settlement-engine): remove circular dependency with api-gateway#1

Open
mayborn005 wants to merge 1 commit into
mainfrom
fix/issue-247-circular-service-dependency
Open

fix(settlement-engine): remove circular dependency with api-gateway#1
mayborn005 wants to merge 1 commit into
mainfrom
fix/issue-247-circular-service-dependency

Conversation

@mayborn005

Copy link
Copy Markdown
Owner

Summary

  • Remove HTTP call from /api/settlements/reconcile endpoint to api-gateway, eliminating the circular dependency
  • Replace cross-service comparison with local consistency validation that checks mathematical accuracy, fee calculations, and merchant references
  • Remove the hand-rolled signHS256 JWT generation function that was only used for this HTTP call
  • Add comprehensive test suite with 20 tests verifying reconciliation works without any HTTP calls

Changes

Removed

  • signHS256() function for JWT generation
  • HTTP fetch call to api-gateway/api/settlements
  • Cross-service settlement record comparison logic

Added

  • Local consistency check that validates:
    • Mathematical consistency: grossAmount - feeAmount = netAmount
    • Fee calculation accuracy: feeAmount matches feeBps applied to grossAmount
    • Merchant reference validity: all settlements reference existing merchants
  • reconciliation.test.ts with 20 unit tests
  • Status breakdown and summary statistics in reconciliation response

Updated Response Format

The reconcile endpoint now returns:

{
  "summary": { "total": 10, "valid": 9, "inconsistent": 1 },
  "statusBreakdown": { "pending": 2, "completed": 8 },
  "totals": { "gross": "1000", "fee": "10", "net": "990" },
  "inconsistencies": [...],
  "reconciliationType": "local_consistency_check"
}

Test plan

  • All 63 settlement-engine tests pass (including 20 new reconciliation tests)
  • Verify reconciliation works without api-gateway running
  • Manual test: call /api/settlements/reconcile endpoint
  • Verify no HTTP calls are made during reconciliation

Closes Betta-Pay#247

Remove HTTP call from /api/settlements/reconcile endpoint to api-gateway.
The reconciliation now performs a local consistency check against the
settlement engine's own database instead of calling the api-gateway.

Changes:
- Remove signHS256 JWT generation function
- Remove HTTP fetch to api-gateway settlement endpoint
- Replace cross-service comparison with local consistency validation:
  - Mathematical consistency: grossAmount - feeAmount = netAmount
  - Fee calculation accuracy: feeAmount matches feeBps
  - Merchant reference validity: settlements reference existing merchants
- Add comprehensive test suite for reconciliation logic (20 tests)
- Update test script to include reconciliation tests

Closes Betta-Pay#247
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.

Circular Service Dependency: Settlement Engine → API Gateway for Reconciliation

2 participants