Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
/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.charge.success, Paystack'ssplit.sharesbecome the order's split settlement: each vendor's amount, the shop's remainder and Paystack's fee.+254 712 345 678is sent to Paystack as0712345678, which is the form Paystack accepts.false.Changes
packages/paystack/src/provider.ts:splits: true;splitFor(validates core's shares, then builds the flat split);splitSettlementFrom;listPayoutBanks,resolvePayoutAccountandcreatePayoutAccount.packages/paystack/README.md: a Multi-vendor row; "Not supported" now lists only subscriptions.@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 fromcharge.success, the bank list (paged, banks and mobile money once each), the shop-country rule, the account look-up (including the+254form), 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 signedcharge.successrecords 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.lockis 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
splitForrefuses 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./bank/resolveonly 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 bank001resolves.)@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.