Skip to content

feat(paystack): multi-vendor payments with Paystack splits - #152

Open
moset15 wants to merge 1 commit into
emdashCommerce:mainfrom
FIKANOVA:feat/paystack-vendor-splits
Open

moset15 wants to merge 1 commit into
emdashCommerce:mainfrom
FIKANOVA:feat/paystack-vendor-splits

Conversation

@moset15

@moset15 moset15 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

What and why

A shop with vendors can't take Paystack payments split between them. The package declares capabilities.splits: false, so core's split plan from #101, #103 and #105 never reaches Paystack, and the Vendors page can't set up a Paystack payout account.

This PR implements the generic split capability for Paystack, using core's design as it is. Flutterwave already does the same.

Part of the roadmap in #108.

Behaviour

  • Vendor payout accounts. On the Vendors page, a vendor gets a Paystack subaccount: choose a bank or mobile money (M-PESA, Airtel and Telkom in Kenya; MTN, AirtelTigo and Vodafone in Ghana), look up the account holder where Paystack offers it (Nigeria and Ghana), create. Subaccounts are in the shop's own Paystack country, so the package only offers that country's banks; a vendor in another country gets a clear message instead of Paystack's error. A subaccount Paystack hasn't verified yet is reported as unverified.
  • At checkout, each vendor's exact share goes to their subaccount as a flat split on /transaction/initialize. The shop keeps the rest and pays Paystack's fee (bearer_type: "account"), as with Stripe Connect. Paystack records it as a dynamic split for that one payment, kept apart from the split groups merchants create in the dashboard.
  • On charge.success, Paystack's split.shares become the order's split settlement: each vendor's amount, the shop's remainder and Paystack's fee.
  • Refunds go through Paystack as before and come out of the shop's balance. Core's order page already warns that vendor shares aren't pulled back.
  • A mobile number typed as +254 712 345 678 is sent to Paystack as 0712345678, which is the form Paystack accepts.
  • No change for carts without vendor items. Subscriptions stay false.

Changes

  • packages/paystack/src/provider.ts: splits: true; splitFor (validates core's shares, then builds the flat split); splitSettlementFrom; listPayoutBanks, resolvePayoutAccount and createPayoutAccount.
  • packages/paystack/README.md: a Multi-vendor row; "Not supported" now lists only subscriptions.
  • Changeset: minor for @dashcommerce/paystack.

No core change. The package's peer range is unchanged.

Tests

  • packages/paystack/test/splits.test.ts (new): the split sent at checkout, no split without vendor items, bad shares refused before Paystack is called, settlement from charge.success, the bank list (paged, banks and mobile money once each), the shop-country rule, the account look-up (including the +254 form), subaccount creation with a masked account number, and unverified subaccounts.
  • packages/paystack/test/core-integration.test.ts: through core's real routes, a two-vendor cart sends both shares to Paystack, and a signed charge.success records what Paystack paid each vendor on the order.

15 of the new tests fail without the change (upstream's provider.ts, tests kept). Suites run locally: paystack 123, core 438, flutterwave 137, all passing. tsc --noEmit, Biome and the build are clean on the changed files; bun.lock is unchanged.

Also tested by hand on a running shop (EmDash 1.6, Paystack test mode, KES). A vendor with an M-PESA subaccount, one of their products, paid with M-PESA in test mode. Paystack's transaction shows a flat split: KES 1,350.89 to the subaccount, KES 127.58 to the shop and KES 22.52 fee on the shop. The admin order shows the same three figures and the refund note. The subaccount was unverified, and the split still settled to it.

Review points

  • Why a flat split, not a percentage? Core's allocations are exact minor-unit amounts per vendor, and a cart can mix vendors and the shop's own items. A flat split sends exactly those amounts; a percentage would round.
  • Is the split safe? splitFor refuses shares that exceed the charge, a missing subaccount code or a non-positive share before calling Paystack, so a bad plan fails checkout rather than settling everything to the shop.
  • Account look-up outside Nigeria and Ghana. Paystack's /bank/resolve only works in Nigeria and Ghana, and core's Vendors form makes Verify compulsory for any provider with a look-up. So a Kenyan or South African shop can't create a vendor's account from the form yet (pasting the subaccount code from the Paystack dashboard works). That's a small core change to the form, so it's in its own PR: feat(core,paystack): vendor payout accounts where the provider can't look up names #153. (Note: Paystack test mode also allows only 3 live look-ups a day; after that only test bank 001 resolves.)
  • Vendor payouts settle on Paystack's normal schedule. Payout to a live bank or M-PESA account isn't verified here, only in test mode.

@alexasomba, as we agreed on #108: this builds on #101, #103 and #105 without changing them. Your fixtures and a review would be very welcome; if your cases cover something these tests don't, I'll fold them in.

Implements the generic split capability from emdashCommerce#101/emdashCommerce#103/emdashCommerce#105 for Paystack:

- Vendors are onboarded as Paystack subaccounts through listPayoutBanks,
  resolvePayoutAccount and createPayoutAccount: banks and mobile money in
  the shop's own Paystack country (M-PESA, Airtel and Telkom in Kenya).
  A vendor outside that country gets a clear message. Unverified
  subaccounts are reported as such.
- Core's per-vendor shares go to Paystack as a flat split on
  /transaction/initialize; the shop keeps the rest and bears the fee.
- charge.success split shares become the order's split settlement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant