Skip to content

feat(core): provider-managed payout account onboarding - #103

Open
alexasomba wants to merge 8 commits into
emdashCommerce:mainfrom
alexasomba:feat/provider-payout-onboarding
Open

alexasomba wants to merge 8 commits into
emdashCommerce:mainfrom
alexasomba:feat/provider-payout-onboarding

Conversation

@alexasomba

@alexasomba alexasomba commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of the Flutterwave set described in #97. Item 6. Builds on #101 (vendor payout accounts). Generic core; no Flutterwave code.

Why

The Flutterwave create-subaccount API takes the bank, account number, country, business details and a default split, and returns the RS_… id. Asking the merchant to create that in the Flutterwave dashboard and paste the id is a v1. This adds the seam so a provider can do it from Vendors, with the account name verified when the provider supports it.

What

  • VendorPaymentAccount gains accountName, verified, bankName, bankCode, country, maskedAccountNumber, metadata and createdAt. The full account number is never stored. verified: false means the provider created a usable account it has not verified; core still accepts it for splits.
  • PaymentProvider gains three optional methods:
    • listPayoutBanks(ctx, country, credentials)
    • resolvePayoutAccount(ctx, { accountNumber, bankCode }, credentials)
    • createPayoutAccount(ctx, { accountNumber, bankCode, country, businessName, businessEmail, businessMobile, splitType, splitValue, … }, credentials)
  • Admin routes: GET admin/vendors/payout-banks, POST admin/vendors/payout-account/resolve, POST admin/vendors/payout-account. They load the provider's saved credentials, validate the input, create the account, and store the masked result on the vendor. A second create is refused unless replace: true; replacing still depends on the provider accepting the new account.
  • Vendors page: for a provider that implements the methods, the edit modal shows country → bank or mobile money → account or mobile number → Verify account (only when the provider supports it) → business details → default split type/value → Create payout account. The country starts from the store's default currency. The stored account is shown with its masked number, status and an unverified marker when applicable. The manual account id remains for providers without onboarding.
  • _providers exposes payoutOnboarding and payoutVerification, so the UI only renders the form when the provider can create an account, and only requires verification when the provider can resolve names.

API facts this is built on (checked, not assumed)

  • Flutterwave: GET /v3/banks/{country} returns { code, name }; POST /v3/accounts/resolve with account_number + account_bank returns account_name; POST /v3/subaccounts requires account_bank, account_number, business_name, country, business_mobile, split_value (and business_email in practice), with split_type optional.
  • The subaccount default can be percentage or flat; DashCommerce still overrides it per payment with the exact vendor amount, so the default is only a fallback.

Tests

  • 353 core tests pass, including 8 new ones: banks, resolve, create + stored metadata, duplicate/replace, provider without onboarding, validation, gate, payoutOnboarding/payoutVerification in _providers, an account created without a resolver, and an active-but-unverified account.
  • Typecheck clean; changeset minor.

Review response (moset15)

  • Verification is optional. _providers exposes payoutVerification; the form requires the resolved name only when the provider implements resolvePayoutAccount. Otherwise it saves the account unverified and says so. The core route only rejects a missing name when the provider can verify.
  • Status. A usable-but-unverified account is status: "active" plus verified: false on VendorPaymentAccount/CreatedPayoutAccount. Core's split check still only requires active, so Paystack's is_verified: false, active: true is usable, and the Vendors page shows unverified. No new status value.
  • Default country. The form starts on the store's default-currency country (KES → KE, NGN → NG, GHS → GH, ZAR → ZA, …) instead of hardcoded NG.
  • M-PESA. listPayoutBanks may return mobile-money channels; the bank picker is searchable and labelled "Bank or mobile money", and the account field is "Account or mobile number". No core change is needed for Paystack to pay a vendor to M-PESA.
  • Removal. "Remove from vendor" detaches the account locally; the provider account is unchanged. The form says so.

Next

The Flutterwave package (#107) implements the three methods using the endpoints above and ships the form in Vendors. Paystack can implement the same three methods for its subaccounts without another core change.

@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.

The three methods map onto Paystack too: listPayoutBanks to GET /bank, resolvePayoutAccount to GET /bank/resolve, createPayoutAccount to POST /subaccount (business_name, settlement_bank, account_number, percentage_charge).

Two things in the Vendors form:

  1. Verification is required even when the provider can't verify. resolvePayoutAccount is optional on the interface, but the form's valid needs accountName !== null, so a provider without it, or a country where account lookup isn't supported, can never create an account. Suggest requiring verification only when the provider implements it, and storing the account unverified otherwise. In Kenya the lookup does work: in Paystack test mode it returned the account name for a Kenyan bank account and for an M-PESA number. South Africa is the case to allow for, where Paystack checks accounts with POST /bank/validate and an ID document instead.
  2. The form starts on Nigeria (useState("NG")). Starting on the shop's default country (or the provider's first country) saves Kenyan, Ghanaian and South African merchants a step.

M-PESA payouts fit the seam as is. Paystack lists M-PESA as a payout channel (GET /bank?currency=KES&type=mobile_money), and a subaccount can settle to an M-PESA number; I created one in test mode. So the Paystack package can return M-PESA alongside the banks from listPayoutBanks, and Kenyan vendors can be paid to M-PESA with no core change. One mapping question for providers: Paystack creates subaccounts as unverified (is_verified: false) but active: true. Should a provider report that as "active" (#101 refuses anything else), or is there a status for "usable but not yet verified"?

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

Copy link
Copy Markdown
Contributor Author

@moset15 thanks — both form points are in, and the status question has a separate flag rather than a new status.

  • Verification is optional. _providers now exposes payoutVerification; the form requires the resolved name only when the provider implements resolvePayoutAccount. Otherwise it saves the account unverified and says so. The core route only rejects a missing name when the provider can verify.
  • Status. A usable-but-unverified account is status: "active" plus verified: false on VendorPaymentAccount / CreatedPayoutAccount. Core's split check still only requires active, so Paystack's is_verified: false, active: true is usable, and the Vendors page shows "unverified". No new status value.
  • Default country. The form starts on the store's default-currency country (KES → KE, NGN → NG, GHS → GH, ZAR → ZA, …) instead of NG. There is no store-country setting yet, so currency is the best signal; adding one is a small follow-up if you want it.
  • M-PESA. Agreed: listPayoutBanks can return mobile-money channels. The bank picker is searchable and labelled "Bank or mobile money", the account field is "Account or mobile number", and no core change is needed for Paystack to pay a vendor to M-PESA.
  • Removal. "Remove from vendor" detaches the account locally; the provider account is unchanged, and the form says so.

Pushed in 5ceb2e4; #107 is merged forward. The Paystack mapping you described (GET /bank, GET /bank/resolve, POST /subaccount) is exactly what the seam expects.

@alexasomba

Copy link
Copy Markdown
Contributor Author

Follow-up on the replace caveat I raised: onboarding is now idempotent in #107 (0ed388b). If Flutterwave answers a create with 400/409, the package lists /v3/subaccounts filtered by account_number and account_bank, and returns the existing RS_… if it matches; otherwise it rethrows the original error. Matching on the account rather than the error text means a reworded Flutterwave message does not break it. Package tests: 101.

@cavewebs cavewebs 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.

This looks good. I will take it through #107 rather than merging it on its own, so we avoid the sibling conflicts with #105.

cavewebs added a commit that referenced this pull request Nov 27, 2026
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_subaccount` amount, 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.splits`** on `PaymentProvider`, and `splits` in
`unsupportedHostedCheckoutFeatures`. 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`) and **`platformRemainderMinor`**. 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.
- **Admin API**: `POST admin/vendors/item` creates a vendor without
Stripe; `PATCH` accepts `paymentAccount` or `paymentAccounts` to add,
replace or remove an account. Vendor routes open when Connect is on
**or** a split-capable provider is registered.
- **Settings** exposes each provider's `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.
- **Product editor**: the vendor picker and the save-time validation now
accept a split-capable provider's active payout account, not only Stripe
`chargesEnabled`. A Flutterwave-only store can assign products to
vendors without turning on Stripe Connect.

## What does not change

- Stripe Connect: single-vendor destination charges are untouched;
multi-vendor Stripe carts still return 501.
- A cart without vendor items sends no allocations.
- Vendor records created by Stripe onboarding keep working;
`paymentAccounts` is additive.

## Tests

- **345 core tests pass**, including 18 new ones for split computation
and the vendor API, 5 for product-to-vendor assignment, and 4 that run
the real `checkout/create-session` route:
- two vendors at 10% → `135000` each, platform remainder `180000`
(platform item + fees);
  - no vendor items → no allocations;
  - a provider without `splits` → 409 naming `splits`;
  - a vendor with no account → 409 naming the vendor.
- Split computation covers fees, overrides, tax/shipping/platform items,
missing vendors, pending/disabled accounts, currency mismatch, zero
shares, a platform-absorbed discount and a discount larger than the
platform remainder.
- Vendor API covers the gate, create, add/replace/remove,
unknown/non-splitting providers, bad references/status, Stripe status
untouched, search by account reference, and creating two vendors without
a Stripe account.
- `tsc --noEmit` clean; Biome clean on the touched files.

## Next

The Flutterwave package is
[#107](#107), which
builds on this.
[#103](#103) (payout
onboarding) and
[#105](#105)
(settlement) also build on this.

## Review response (moset15)

- **Vendor unique index:** `Vendor.stripeAccountId` is now optional and
`createVendor` omits 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 an `acct_…`. Test: two vendors through
`admin/vendors/item`. The Stripe Refresh action is hidden when a vendor
has no Stripe account.
- **Generic comments:** `accountReference` and `capabilities.splits` now
name Paystack's `ACCT_…` as well as Flutterwave's `RS_…`.
- **Fee bearer:** the README provider-author section says to keep the
fee on the platform so vendor shares stay exact.
- **Coupons:** intended. Shares are computed on pre-discount line
subtotals, matching `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

- `onboardingStatus` is set to `active` for 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.
- The Vendors page only shows payout-account fields for providers that
declare `splits`; Connect-only stores see the page exactly as before.
- API-driven payout onboarding is #103, implemented for Flutterwave in
#107. The manual `RS_…` field remains as a fallback.
@alexasomba

Copy link
Copy Markdown
Contributor Author

The payout verification fix is in #107 (a38d530). The form ties each verification result to the submitted account details, so a late response can’t mark an edited account as verified.

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.

3 participants