Skip to content

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

Merged
therealjhay merged 2 commits into
Betta-Pay:mainfrom
mayborn005:fix/issue-247-circular-service-dependency
Jul 28, 2026
Merged

fix(settlement-engine): remove circular dependency with api-gateway#418
therealjhay merged 2 commits into
Betta-Pay:mainfrom
mayborn005:fix/issue-247-circular-service-dependency

Conversation

@mayborn005

Copy link
Copy Markdown
Contributor

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 #247

Description

Please include a clear, concise summary of the changes introduced by this pull request. Explain the rationale behind the solution, any design trade-offs made, and context on how the changes achieve the goal.

Fixes / Closes: # (issue number)


Type of Change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring / Performance (clean-up or performance optimization without behavioral changes)
  • Documentation / CI (changes to docs, workflows, config files)

Verification & Test Plan

Please outline how you verified these changes. Include steps to reproduce, test scripts, or command logs where applicable.

Automated Tests

For example: cargo test in contract package, pnpm test in backend.

# Provide the commands run to test the code

Manual Verification


Sub-System Checklist

1. Smart Contracts (BettaPay-Contract)

  • Code compiles without warnings (cargo build --release --target wasm32-unknown-unknown)
  • Cargo test suite passes locally (cargo test)
  • Emits events for state changes
  • Implemented proper authorization controls (auth.require_auth())

2. Backend Services (BettaPay-Backend)

  • Prisma models updated and migrated (if database schema changes)
  • Zod validation checks added/updated
  • API routes and services build successfully (pnpm build)
  • Local env variables updated in .env.example

3. Frontend Dashboard (BettaPay-Frontend)

  • Local build completes successfully (pnpm build)
  • Focus states, labels, and aria attributes tested for accessibility
  • No regression on styling or components
  • Env parameters documented in .env.local

Checklist

  • My code follows the style guidelines of this project (run formatters/linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

zeemscript and others added 2 commits July 20, 2026 17:30
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
@therealjhay
therealjhay merged commit 4229308 into Betta-Pay:main Jul 28, 2026
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

3 participants