Skip to content

feat(core): split settlement and refunds - #105

Open
alexasomba wants to merge 8 commits into
emdashCommerce:mainfrom
alexasomba:feat/provider-split-settlement
Open

alexasomba wants to merge 8 commits into
emdashCommerce:mainfrom
alexasomba:feat/provider-split-settlement

Conversation

@alexasomba

@alexasomba alexasomba commented Nov 24, 2026 •

Copy link
Copy Markdown

Part of the Flutterwave set described in #97. Items 8 and 9. Builds on #101. Generic core; no Flutterwave code. The split-refund guard from #112 is folded in; no review had started there.

Why

Flutterwave's verify response carries meta.split_settlement_info, which says what each subaccount actually earned and the platform's commission. Core was discarding it, so a merchant could see the vendor split at checkout but not what the provider settled. This records the provider's own numbers on the order.

What

  • NormalizedPaymentEvent charge.succeeded gains splitSettlement: allocations (accountReference, amountMinor), platformRemainderMinor, providerFeeMinor, currency and the raw payload.
  • Order.providerSplits stores the same in Money, with the account reference mapped to a vendor when core can resolve it from Vendor.paymentAccounts.
  • The webhook records it after the order is written. A failure is logged and does not make the webhook retry; the order is already complete, and a retry would be answered as a duplicate.
  • The admin order detail shows a Split settlement card: vendor (or “Unmatched account”), account reference, settled amount, platform remainder and provider fee.

What does not change

  • The vendor shares core computed. The provider's settlement is recorded for reconciliation, never used to reprice the order.
  • Orders without a settlement, and Stripe orders, are unchanged.

Tests

  • 349 core tests pass, including 4 new ones:
    • a signed webhook with a settlement creates the order and stores providerSplits with both account references mapped to v1/v2, amounts in minor units, platform remainder and provider fee;
    • a settlement-free event creates the order with no providerSplits;
    • a provider declaring splitRefunds: false is refused before the call and writes no refund row;
    • a provider that does not declare it keeps the existing refund behaviour.
  • Typecheck clean; changeset minor.

Split refunds (folded in from #112)

A split payment cannot always be refunded through the provider from DashCommerce. Flutterwave answers a split refund with 400 "Refund request successfully logged" and no refund id; Stripe Connect refunds work, but the money comes from the platform balance and vendor shares are not clawed back.

  • PaymentProviderCapabilities.splitRefunds: optional. Missing means yes (existing Stripe behaviour). false means the provider cannot refund a split charge.
  • refundOrder refuses before loading credentials or calling the provider when order.providerSplits is present and the provider declares false, with a message pointing to its dashboard.
  • Order detail → Split settlement warns that the refund comes from the platform balance and vendor shares are not recovered automatically.
  • The Flutterwave package declares splitRefunds: false in feat(flutterwave): Flutterwave payment provider package #107.

Next

The Flutterwave package (#107) parses meta.split_settlement_info and app_fee into this event shape, so the real split we already tested is recorded on the order.

@moset15 moset15 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fits Paystack directly. charge.success for a split payment carries split.shares: subaccounts[].amount with subaccount_code → allocations, integration → platformRemainderMinor, paystack → providerFeeMinor. No change needed from the Paystack side.

createVendor stored stripeAccountId: "" and the field has a unique
index, so the second vendor failed. The field is now optional and
omitted when there is no Stripe account; a missing field is NULL.

Also documents the coupon rule for split allocations (the platform
absorbs a cart-wide discount; a larger one is a 409) and makes the
allocation comments generic for Paystack.
@alexasomba alexasomba changed the title feat(core): record provider split settlements on orders feat(core): split settlement and refunds Nov 25, 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.

2 participants