Repository navigation
feat(core): split payments across vendor payout accounts - #101
alexasomba wants to merge 4 commits into
Conversation
moset15
left a comment
There was a problem hiding this comment.
Checked this against Paystack's split API, since Paystack will build on the same seam.
It fits Paystack as is. allocations maps onto Paystack's dynamic split at initialise: split: { type: "flat", bearer_type: "account", subaccounts: [{ subaccount: accountReference, share: amountMinor }] }. Flat shares are in subunits and must sum to at most the amount, which platformRemainderMinor >= 0 already guarantees. bearer_type: "account" keeps Paystack's fee on the platform, the same as Connect, so a vendor gets exactly their share. A multi-vendor cart is one split with several subaccounts. paymentAccounts[providerId].accountReference holds Paystack's ACCT_… code.
Two small points:
- The comments on
accountReferenceandcapabilities.splitsname Flutterwave only. Something like "a provider subaccount, e.g. FlutterwaveRS_…or PaystackACCT_…" keeps the type generic. - Fee bearer isn't part of the seam, which is right, but it's worth one line in the README's provider-author section: a provider should keep its fee on the platform so vendor shares stay exact. Paystack and Flutterwave both default that way, but a later provider might not.
One question, not a blocker: shares are computed on pre-discount line subtotals, so a cart-wide coupon comes out of the platform's remainder, and a large one makes the allocations exceed the total (409). That matches the Connect plan in split.ts. Is that the intended rule for coupons on vendor items?
|
One more from testing against Paystack, separate from my earlier review: a shop without Stripe can only create one vendor.
Suggested fix: make A test that creates two vendors through |
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.
|
@moset15 thanks for the review and the two-vendor catch — both are addressed.
Pushed in 3650bba (fix) and e6ba737 (notes); #103/#105/#107 are merged forward. Thanks for checking the Paystack mapping too — the flat-share mapping you described is exactly what the seam was meant to support. |
Part of the Flutterwave set described in #97. Item 4 — a generic core seam; no Flutterwave code in core.
Why
A cart with vendor-owned items could not be paid by a non-Stripe provider at all, and Stripe Connect deliberately rejects multi-vendor carts. Flutterwave supports splitting one payment into collection subaccounts with an exact
flat_subaccountamount, but core had no way to hand a provider per-vendor amounts.This adds that seam. Core owns the arithmetic; a provider only routes what core supplies.
What
capabilities.splitsonPaymentProvider, andsplitsinunsupportedHostedCheckoutFeatures. A vendor cart is now refused with a readable 409 for a provider that cannot split, instead of silently charging the platform account.InitCheckoutInput.allocations(vendorId,accountReference,amountMinor) andplatformRemainderMinor. Core computes them from trusted cart prices and the vendor's platform fee; providers must not reprice.Vendor.paymentAccounts, keyed by provider id, for providers other than Stripe:accountReference,status, optional settlement currency and label. Stripe Connect keeps its existing fields.computeProviderSplit: groups cart lines by vendor, requires an active account in the cart's currency, applies the vendor/global platform fee, and returns exact minor amounts. It throws merchant-readable errors for a missing vendor, a missing/pending/disabled account, a currency mismatch, a non-positive share, or a cart-wide discount larger than the platform remainder.POST admin/vendors/itemcreates a vendor without Stripe;PATCHacceptspaymentAccountorpaymentAccountsto add, replace or remove an account. Vendor routes open when Connect is on or a split-capable provider is registered.capabilities, and the Vendors page adds a vendor and edits payout accounts when a split-capable provider is active — no Stripe onboarding needed. The Stripe onboarding/refresh/payout routes still require Connect.chargesEnabled. A Flutterwave-only store can assign products to vendors without turning on Stripe Connect.What does not change
paymentAccountsis additive.Tests
checkout/create-sessionroute:135000each, platform remainder180000(platform item + fees);splits→ 409 namingsplits;tsc --noEmitclean; Biome clean on the touched files.Next
The Flutterwave package is #107, which builds on this. #103 (payout onboarding) and #105 (settlement) also build on this.
Review response (moset15)
Vendor.stripeAccountIdis now optional andcreateVendoromits it for non-Stripe vendors. A missing field is NULL, so a shop without Stripe can create any number of vendors; two vendors still cannot share anacct_…. Test: two vendors throughadmin/vendors/item. The Stripe Refresh action is hidden when a vendor has no Stripe account.accountReferenceandcapabilities.splitsnow name Paystack'sACCT_…as well as Flutterwave'sRS_….split.ts; the platform absorbs a cart-wide discount, and a discount larger than the platform remainder is refused with a readable 409 rather than silently reducing a vendor's payout. Tests cover both cases. If you want vendors to bear part of the discount, that is a separate policy change.Review notes
onboardingStatusis set toactivefor a non-Stripe vendor when any provider account is active, so the existing status badge is meaningful. A Stripe vendor's status is never changed by a provider account.splits; Connect-only stores see the page exactly as before.RS_…field remains as a fallback.