Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f8a15c8
feat(flutterwave): Flutterwave payment provider package
alexasomba Nov 24, 2026
82e9a32
fix(flutterwave): keep refunds working when refund history is unavail…
alexasomba Nov 24, 2026
6f81f05
feat(core): a public-key credential for payment providers
alexasomba Nov 24, 2026
0fd7f02
merge: provider public key credential
alexasomba Nov 24, 2026
5e07131
feat(flutterwave): on-page checkout with Flutterwave Inline
alexasomba Nov 24, 2026
422fc82
feat(core): split payments across vendor payout accounts
alexasomba Nov 24, 2026
1faa079
merge: provider split allocations
alexasomba Nov 24, 2026
9a1fd02
feat(flutterwave): split payments across subaccounts
alexasomba Nov 24, 2026
89879d0
test(flutterwave): real split fixture from test mode
alexasomba Nov 24, 2026
69bac92
fix(core): let a split-capable provider assign products to vendors
alexasomba Nov 24, 2026
fb33ca2
merge: product vendor assignment fix
alexasomba Nov 24, 2026
cbdf79b
feat(core): provider-managed payout account onboarding
alexasomba Nov 24, 2026
bee319d
merge: provider payout onboarding
alexasomba Nov 24, 2026
496950a
feat(flutterwave): in-admin payout onboarding and cart discounts
alexasomba Nov 24, 2026
bf57f8a
feat(core): record provider split settlements on orders
alexasomba Nov 24, 2026
98ab71d
merge: provider split settlement
alexasomba Nov 24, 2026
4189bd5
feat(flutterwave): record split settlements on the order
alexasomba Nov 24, 2026
d7a6f6e
fix(flutterwave): surface the split-refund logged message
alexasomba Nov 24, 2026
3559b37
docs(flutterwave): record the split-refund test-mode result
alexasomba Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/flutterwave-on-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@dashcommerce/flutterwave": minor
---

On-page checkout with Flutterwave Inline.

- Declares `checkoutStyles: ["hosted", "on_page"]` and a `publicKey` credential (`FLWPUBK_…`), saved by core as `settings:flutterwavePublicKey`.
- With checkout set to "On your page", `initCheckout` returns `on_page` with the public key, `tx_ref`, amount in major units and customer details. No server-side payment is created; Inline creates the transaction in the browser.
- New `./checkout-client` entry registers Flutterwave Inline on `window.DashCommerceCheckoutClients.flutterwave`, loads `checkout.flutterwave.com/v3.js` only when the customer presses Pay, and maps `callback`/`onclose` to finished/closed. Orders still come only from the signed webhook and the live verify.
- On-page checkout refuses to start, with a message naming the setting, when the public key is missing.
10 changes: 10 additions & 0 deletions .changeset/flutterwave-payout-onboarding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@dashcommerce/flutterwave": minor
---

In-admin vendor payout onboarding and cart discounts.

- Implements `listPayoutBanks`, `resolvePayoutAccount` and `createPayoutAccount`: the Vendors page lists banks, verifies the account name, creates the Flutterwave collection subaccount and stores the masked result. The full account number is never stored.
- Subaccount defaults support `percentage` or `flat`; DashCommerce still overrides each payment with the exact vendor amount, so the shares stay exact.
- Declares `capabilities.coupons: true`. Cart discounts are applied to the amount Flutterwave charges; no provider-side coupon object is created.
- Needs the core release with the payout onboarding seam (`listPayoutBanks`, `resolvePayoutAccount`, `createPayoutAccount`).
14 changes: 14 additions & 0 deletions .changeset/flutterwave-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@dashcommerce/flutterwave": minor
---

New package: a Flutterwave payment provider for DashCommerce, built on core's PaymentProvider interface.

- Card, M-Pesa and mobile money through Flutterwave's hosted checkout. Currencies: NGN, USD, GBP, EUR, KES, GHS, ZAR, UGX, TZS, RWF, XOF, XAF, ZMW, MWK and EGP.
- Amounts are converted at the boundary: core keeps minor units, Flutterwave's v3 API charges major units.
- Orders are created only from a signed `charge.completed`, confirmed against Flutterwave before the order is written. `verif-hash` is checked in constant time against the secret hash saved in Settings → Webhooks.
- Repeat and overlapping webhook deliveries run once: each charge and refund event carries an event id core can deduplicate on.
- Refunds by transaction id or `tx_ref`, guarded against duplicates on retry, with Flutterwave's refund webhook moving each refund to succeeded or failed.
- "Test Flutterwave connection" in Settings checks the saved key in test or live mode with a read-only balances call.

Needs `@dashcommerce/core` 0.4.0 or later. Register it with `import "@dashcommerce/flutterwave"` in a server module, add `api.flutterwave.com` to `allowedHosts`, and point Flutterwave's webhook at `…/checkout/webhook?provider=flutterwave`; see the package README.
9 changes: 9 additions & 0 deletions .changeset/flutterwave-split-settlement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@dashcommerce/flutterwave": minor
---

Record Flutterwave's split settlement on the order.

- `charge.succeeded` parses `meta.split_settlement_info` and `app_fee` into core's `splitSettlement`: per-subaccount earnings, the platform commission and the provider fee, converted to minor units.
- Core stores it on `Order.providerSplits`, mapping each subaccount reference to its vendor; the admin order detail shows a "Split settlement" card.
- The vendor shares DashCommerce computed are never repriced by the settlement; it is recorded for reconciliation only.
10 changes: 10 additions & 0 deletions .changeset/flutterwave-splits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@dashcommerce/flutterwave": minor
---

Split payments across vendor subaccounts.

- Declares `capabilities.splits`. When core sends `allocations`, each becomes a Flutterwave `subaccounts` item with `transaction_charge_type: "flat_subaccount"` and the exact major-unit amount, for hosted checkout and Inline.
- On-page checkout carries the split as JSON in the client payload; the browser client parses it and refuses a malformed split rather than opening an unsplit payment.
- Validates every share before calling Flutterwave: no empty account, no non-positive amount, no total above the checkout amount, no negative platform remainder.
- Needs a core release with the split allocation seam (`capabilities.splits`, `allocations`, `platformRemainderMinor`).
10 changes: 10 additions & 0 deletions .changeset/provider-payout-onboarding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@dashcommerce/core": minor
---

Provider-managed payout onboarding and richer vendor payout accounts.

- `VendorPaymentAccount` gains `accountName`, `bankName`, `bankCode`, `country`, `maskedAccountNumber`, `metadata` and `createdAt`.
- `PaymentProvider` gains optional `listPayoutBanks`, `resolvePayoutAccount` and `createPayoutAccount`, so a provider can onboard a vendor's payout account without sending the merchant to its dashboard.
- `admin/vendors/payout-banks`, `admin/vendors/payout-account/resolve` and `admin/vendors/payout-account` expose that to the Vendors page, which renders a country/bank/account form for providers that implement it.
- The stored account keeps the resolved account name, bank and a masked account number; the full number is never persisted.
9 changes: 9 additions & 0 deletions .changeset/provider-public-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@dashcommerce/core": minor
---

Let a payment provider save a browser public key.

- `PaymentProviderCredentials.publicKey` and `credentialFields.publicKey`, saved as `settings:<id>PublicKey` and validated against the prefixes the provider declares. Providers that need it for on-page checkout (Flutterwave Inline) can hand it to their browser client; nothing else changes for providers that do not.
- Settings shows the field only for a provider that declares it, beside the secret key and webhook secret. A provider that does not declare one cannot have a public key saved, and its settings row is unchanged.
- `loadPaymentProviderCredentials` returns `publicKey` when one is set.
11 changes: 11 additions & 0 deletions .changeset/provider-split-allocations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@dashcommerce/core": minor
---

Let a payment provider split one payment across vendor payout accounts.

- `capabilities.splits` and `InitCheckoutInput.allocations` / `platformRemainderMinor`. Core computes exact per-vendor minor amounts from trusted cart prices and the vendor's platform fee; a provider only routes them to the account reference core supplies.
- `Vendor.paymentAccounts`, keyed by provider id, for providers other than Stripe: `accountReference`, `status`, and an optional settlement currency and label. Stripe Connect keeps its existing fields.
- `admin/vendors/item` accepts `POST` to create a vendor without Stripe, and `PATCH` with `paymentAccount` / `paymentAccounts` to add, replace or remove a provider account. Vendor routes open when Connect is on **or** a split-capable provider is registered.
- Settings exposes each provider's `capabilities`. The Vendors page adds a vendor and edits payout accounts when a split-capable provider is active, without requiring Stripe.
- A vendor cart is refused with a readable 409 when the active provider cannot split, or when a vendor has no active account for it, instead of silently charging the platform account.
10 changes: 10 additions & 0 deletions .changeset/provider-split-settlement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@dashcommerce/core": minor
---

Record provider-reported split settlements on the order.

- `NormalizedPaymentEvent` `charge.succeeded` gains `splitSettlement`: per-account minor amounts, the platform remainder and the provider fee, when the provider reports them.
- `Order.providerSplits` stores it with the account reference mapped to a vendor when core can resolve it, for reconciliation. It never changes the vendor shares core computed.
- The webhook records it after the order is written. A failure is logged and does not make the webhook retry, because the order is already complete.
- The admin order detail shows a "Split settlement" card when the order has one.
14 changes: 14 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ Stripe is built in. A gateway package (for example `@dashcommerce/paystack`) reg
emdash({ plugins: [dashcommerce({ allowedHosts: ["api.paystack.co"] })] });
```

3. **Choose the provider and enter its keys** in Settings → Payment provider. They are saved as `settings:<id>SecretKey` and `settings:<id>WebhookSecret`, masked like Stripe's.
3. **Choose the provider and enter its keys** in Settings → Payment provider. They are saved as `settings:<id>SecretKey` and `settings:<id>WebhookSecret` (plus `settings:<id>PublicKey` when the provider declares one), masked like Stripe's.
4. **Point the provider's webhooks** at `/_emdash/api/plugins/dashcommerce/checkout/webhook?provider=<id>`.

For provider authors, `PaymentProvider` can declare:

- `credentialFields`: the label, accepted prefixes and help text for the settings form.
- `credentialFields`: the label, accepted prefixes and help text for the settings form. A `publicKey` field is shown only when declared, for on-page checkout that needs the browser key (Flutterwave Inline); `credentials.publicKey` carries the saved value.
- `webhookHeaders`: the headers that identify its webhooks, besides `x-<id>-signature`. `verifyWebhook` receives every request header, and `credentials` (the provider's saved secret key and webhook secret) for headers signed with the API key rather than the webhook secret.
- `checkConnection`: one read-only call with the saved keys, behind a "Test connection" button in Settings. Return `{ ok, message }`, with `ok: false` and a message the merchant can act on for a wrong or under-permitted key.
- `capabilities.splits`: core computes `allocations` (`vendorId`, `accountReference`, `amountMinor`) and `platformRemainderMinor` when the cart has vendor-owned items. Vendors store their payout account under `paymentAccounts[providerId]`; the provider only routes the amounts core supplies.
- `listPayoutBanks`, `resolvePayoutAccount`, `createPayoutAccount`: optional provider-managed payout onboarding. The Vendors page lists banks, verifies the account name and creates the account; core stores the masked result on the vendor.
- `splitSettlement` on a `charge.succeeded` event: optional provider-reported per-account amounts, platform remainder and fee. Core stores it on `Order.providerSplits` for reconciliation; it never changes the shares core computed.

`parseWebhookEvent` may return `refund.updated` to move a pending refund to `succeeded` or `failed`. A failed refund stops counting against its order: the refunded total, payment status and order status are worked out again, and stock the refund put back is taken back off.

Expand Down
79 changes: 45 additions & 34 deletions packages/core/src/admin/fields/VendorSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@
* context (field definition, entry metadata) without needing changes here.
*
* Behaviour:
* - Reads `settings:connectEnabled` via the admin settings API on mount.
* - When multi-vendor is off, renders an info banner instead of the picker.
* - When on, fetches `admin/vendors` and renders a searchable Combobox of
* active/pending vendors, dimming entries with `chargesEnabled=false`.
* - Reads `settings:connectEnabled` and the registered providers' `splits`
* capability via the admin settings API on mount.
* - Marketplace mode is Stripe Connect **or** a provider that can split
* payments (Flutterwave subaccounts).
* - When neither is on, renders an info banner instead of the picker.
* - When on, fetches `admin/vendors` and renders a searchable Combobox,
* dimming vendors with no active payout account.
*/

import { useEffect, useMemo, useState } from "react";
import {
Alert,
Combobox,
FormField,
Loading,
usePluginAPI,
type ComboboxOption,
} from "../kit";
import type { Vendor } from "../../types";
import { Alert, Combobox, type ComboboxOption, FormField, Loading, usePluginAPI } from "../kit";

export interface VendorSelectProps {
value?: string | null;
Expand All @@ -35,7 +31,9 @@ export interface VendorSelectProps {
export function VendorSelect(props: VendorSelectProps) {
const api = usePluginAPI();
const [vendors, setVendors] = useState<Vendor[] | null>(null);
const [connectEnabled, setConnectEnabled] = useState<boolean | null>(null);
const [marketplaceEnabled, setMarketplaceEnabled] = useState<boolean | null>(null);
const [connectEnabled, setConnectEnabled] = useState(false);
const [splitsProviders, setSplitsProviders] = useState<Array<{ id: string; label: string }>>([]);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
Expand All @@ -44,22 +42,31 @@ export function VendorSelect(props: VendorSelectProps) {
try {
const settings = await api.get<Record<string, unknown>>("admin/settings");
if (!alive) return;
const on = settings.connectEnabled === true;
setConnectEnabled(on);
if (on) {
const connect = settings.connectEnabled === true;
const providers = Array.isArray(settings._providers)
? (settings._providers as Array<{
id: string;
label: string;
capabilities?: { splits?: boolean };
}>)
: [];
const splits = providers
.filter((provider) => provider.capabilities?.splits === true)
.map((provider) => ({ id: provider.id, label: provider.label }));
const enabled = connect || splits.length > 0;
setConnectEnabled(connect);
setSplitsProviders(splits);
setMarketplaceEnabled(enabled);
if (enabled) {
try {
const res = await api.get<{ items: Vendor[] }>("admin/vendors");
if (alive) setVendors(res.items ?? []);
} catch (err) {
if (alive)
setError(
err instanceof Error ? err.message : "Could not load vendors",
);
if (alive) setError(err instanceof Error ? err.message : "Could not load vendors");
}
}
} catch (err) {
if (alive)
setError(err instanceof Error ? err.message : "Could not load settings");
if (alive) setError(err instanceof Error ? err.message : "Could not load settings");
}
}
load();
Expand All @@ -71,38 +78,42 @@ export function VendorSelect(props: VendorSelectProps) {
const options = useMemo<ComboboxOption[]>(() => {
if (!vendors) return [];
return vendors.map((v) => {
const statusHint =
v.onboardingStatus === "active" && v.chargesEnabled
? "Active"
: v.onboardingStatus === "restricted"
? "Restricted"
: "Pending";
const stripeReady = connectEnabled && v.chargesEnabled;
const providerReady = splitsProviders.some(
(provider) => v.paymentAccounts?.[provider.id]?.status === "active",
);
const ready = stripeReady || providerReady;
const statusHint = ready
? "Active"
: v.onboardingStatus === "restricted"
? "Restricted"
: "Pending";
return {
value: v.id,
label: `${v.name} · ${v.email}`,
hint: statusHint,
disabled: !v.chargesEnabled,
disabled: !ready,
};
});
}, [vendors]);
}, [vendors, connectEnabled, splitsProviders]);

const { value, onChange, field, readOnly } = props;
const label = field?.label ?? "Vendor";

if (connectEnabled === null) {
if (marketplaceEnabled === null) {
return <Loading label="Loading vendor options…" />;
}

if (!connectEnabled) {
if (!marketplaceEnabled) {
return (
<FormField
label={label}
description={field?.help}
{...(field?.required ? { required: true } : {})}
>
<Alert type="info" title="Multi-vendor marketplace is off">
Enable it in Settings → Stripe Connect to assign products to vendors.
Leave this field blank for now.
Enable it in Settings, or install a payment provider that supports split payments, to
assign products to vendors. Leave this field blank for now.
</Alert>
</FormField>
);
Expand Down
59 changes: 58 additions & 1 deletion packages/core/src/admin/pages/OrderDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import {
import { MoneyDisplay } from "../ui/MoneyDisplay";
import { StatusBadge } from "../ui/StatusBadge";
import { EmptyState } from "../ui/EmptyState";
import type { Order, OrderItem, OrderStatus, Refund } from "../../types";
import type {
Order,
OrderItem,
OrderProviderSplitAllocation,
OrderStatus,
Refund,
} from "../../types";
import { T } from "../theme";

// Allowed forward transitions mirrored from `../../orders/status.ts` so the
Expand Down Expand Up @@ -130,6 +136,7 @@ export function OrderDetailPage() {
<BackToOrdersLink />
<OrderHeader order={order} onChanged={reload} />
<ItemsCard items={items} />
<SplitSettlementCard order={order} />
<RefundCard order={order} items={items} onRefunded={reload} />
<RefundHistoryCard refunds={refunds} />
</div>
Expand Down Expand Up @@ -307,6 +314,56 @@ function ItemsCard({ items }: { items: OrderItem[] }) {
);
}

// ────────────────────────────────────────────────────────────────────────────
// Split settlement
// ────────────────────────────────────────────────────────────────────────────

function SplitSettlementCard({ order }: { order: Order }) {
const split = order.providerSplits;
if (!split) return null;
return (
<Card title="Split settlement">
<p style={{ color: T.textMuted, marginTop: 0 }}>
Reported by {split.providerId} when the payment was captured. This records what the
provider says each account earned; it does not change the shares DashCommerce
computed.
</p>
<Table<OrderProviderSplitAllocation>
data={split.allocations}
getRowKey={(a) => a.accountReference}
columns={[
{
key: "vendor",
header: "Vendor",
render: (a) => a.vendorId ?? "Unmatched account",
},
{
key: "account",
header: "Account",
render: (a) => a.accountReference,
},
{
key: "amount",
header: "Settled",
render: (a) => <MoneyDisplay value={a.amount} />,
},
]}
/>
{split.platformRemainder && (
<p style={{ marginBottom: 4 }}>
<strong>Platform remainder:</strong>{" "}
<MoneyDisplay value={split.platformRemainder} />
</p>
)}
{split.providerFee && (
<p style={{ marginBottom: 0 }}>
<strong>Provider fee:</strong> <MoneyDisplay value={split.providerFee} />
</p>
)}
</Card>
);
}

// ────────────────────────────────────────────────────────────────────────────
// Refund panel
// ────────────────────────────────────────────────────────────────────────────
Expand Down
Loading