Skip to content

feat(payments): add cross-account payment splitting - #1849

Merged
github-actions[bot] merged 4 commits into
Smartdevs17:mainfrom
Clement-coder:feat/1720-cross-account-payment-splitting
Oct 19, 2026
Merged

github-actions[bot] merged 4 commits into
Smartdevs17:mainfrom
Clement-coder:feat/1720-cross-account-payment-splitting

Conversation

@Clement-coder

Copy link
Copy Markdown
Contributor

Summary

Implements issue #1720 — cross-account payment splitting.

Revenue sharing between accounts was manual. This PR makes it automatic: a single payment can now be split across multiple destination accounts by percentage with a single API call.

What's in this PR

Layer File
DB migration backend/migrations/005_payment_split_records.sql
Interfaces backend/services/payment/interfaces.ts — PaymentSplit type + splits? on PaymentRequest
Domain errors backend/services/payment/errors.ts — SPLIT_VALIDATION_ERROR error code
Domain service backend/services/payment/domain/PaymentSplitService.ts
HTTP controller backend/services/payment/controller/paymentSplitController.ts
Router backend/services/payment/router/paymentSplitRouter.ts
Server wiring backend/server/createApiServer.ts
Package exports backend/services/payment/index.ts
Tests backend/services/payment/__tests__/PaymentSplitService.test.ts — 46 tests, all passing

Acceptance criteria

  • ✅ Percentages validated to 100 — validateSplits throws SPLIT_VALIDATION_ERROR (HTTP 422) when splits don't sum to 100 (±0.01 tolerance for floating-point)
  • ✅ Each split is recorded — SplitEntryResult per destination in the response; payment_split_records / payment_split_entries tables persist outcomes
  • ✅ Tests — 46 passing unit tests covering validation, amount arithmetic, happy path, partial failure, idempotency key derivation, metadata forwarding, and all HTTP response codes

API

POST /api/v1/payments/split
Content-Type: application/json

{
  "amount": 10000,
  "currency": "USD",
  "idempotencyKey": "order_abc_split",
  "splits": [
    { "destinationAccountId": "acct_merchant", "percentage": 80 },
    { "destinationAccountId": "acct_platform", "percentage": 20 }
  ]
}

Returns 200 when all splits succeed, 207 Multi-Status when at least one fails (remaining splits are still attempted).

Closes #1720

github-actions Bot and others added 4 commits October 19, 2026 11:10
Split a payment across multiple destination accounts by percentage.

- Add PaymentSplitService with validateSplits() enforcing sum=100
- Add PaymentSplitController (POST /api/v1/payments/split)
  - Returns 200 when all splits succeed, 207 on partial failure
  - Returns 422 when percentages do not sum to 100
- Add paymentSplitRouter and mount it in createApiServer
- Add migration 005_payment_split_records.sql with
  payment_split_records + payment_split_entries tables
- Add 46 passing tests covering validation, arithmetic, failure
  handling, idempotency key derivation, and HTTP responses

Closes Smartdevs17#1720
@github-actions
github-actions Bot merged commit 6b1dc7d into Smartdevs17:main Oct 19, 2026
10 of 29 checks passed
@Clement-coder
Clement-coder deployed to security-review October 19, 2026 20:07 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
security-review — ade339c2 Deployed Oct 19, 2026 by Clement-coder via Security Dashboard #1402
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.

Add cross-account payment splitting

1 participant