Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 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
a469e65
chore(flutterwave): consolidate the package changesets
alexasomba Nov 24, 2026
3650bba
fix(core): let a non-Stripe shop create multiple vendors
alexasomba Nov 25, 2026
e521706
merge: non-Stripe vendor fix
alexasomba Nov 25, 2026
45d8681
merge: non-Stripe vendor fix
alexasomba Nov 25, 2026
2741159
merge: non-Stripe vendor fix
alexasomba Nov 25, 2026
e6ba737
docs(core): note the optional Stripe account and the coupon rule
alexasomba Nov 25, 2026
9f94fae
merge: non-Stripe vendor fix notes
alexasomba Nov 25, 2026
5ef0a5d
merge: non-Stripe vendor fix notes
alexasomba Nov 25, 2026
fe544f6
merge: non-Stripe vendor fix notes
alexasomba Nov 25, 2026
5ceb2e4
fix(core): make payout verification optional and default the country
alexasomba Nov 25, 2026
4feeff0
merge: optional payout verification
alexasomba Nov 25, 2026
3b3e521
fix(flutterwave): make payout onboarding idempotent
alexasomba Nov 25, 2026
0ed388b
fix(flutterwave): match existing subaccounts without relying on error…
alexasomba Nov 25, 2026
e6095c1
feat(core): make split refunds explicit
alexasomba Nov 25, 2026
693454f
merge: explicit split refunds
alexasomba Nov 25, 2026
e92f5f7
feat(core): add a provider-neutral subscription seam
alexasomba Nov 25, 2026
7e222ba
feat(flutterwave): support Payment Plans subscriptions
alexasomba Nov 25, 2026
3948156
feat(core): apply subscription updates and provider-aware portal
alexasomba Nov 25, 2026
8b261e9
merge: subscription updates and provider-aware portal
alexasomba Nov 25, 2026
224aade
docs(core): describe the subscription provider seam
alexasomba Nov 25, 2026
7c66b57
merge: subscription provider docs
alexasomba Nov 25, 2026
6b9c492
fix(flutterwave): bill renewals at the recurring line total
alexasomba Nov 25, 2026
0dd89ee
fix(flutterwave): validate on-page checkout before creating a plan
alexasomba Nov 25, 2026
601e62b
fix(core): keep the Stripe portal off provider-managed subscriptions
alexasomba Nov 25, 2026
fe9bc87
fix(core): keep the Stripe portal off provider-managed subscriptions
alexasomba Nov 25, 2026
3846955
merge: provider-managed portal guard
alexasomba Nov 25, 2026
9154287
fix(core): make subscription invoice recording idempotent
alexasomba Nov 25, 2026
9bb56e3
fix(core): make subscription invoice recording idempotent
alexasomba Nov 25, 2026
4fa7d0c
merge: idempotent subscription invoices
alexasomba Nov 25, 2026
d7a23a7
fix(flutterwave): keep repeated subscription cancellations distinct
alexasomba Nov 25, 2026
ae217a2
fix(flutterwave): discard a subscription plan when hosted checkout fails
alexasomba Nov 25, 2026
8ca570b
docs(flutterwave): mention subscriptions in the package metadata
alexasomba Nov 25, 2026
be3495b
fix(core): scope provider subscription ids by provider
alexasomba Nov 25, 2026
0a81937
fix(core): scope provider subscription ids by provider
alexasomba Nov 25, 2026
5e4bd66
merge: scoped subscription ids
alexasomba Nov 25, 2026
60015de
docs(core): note the provider-scoped subscription key
alexasomba Nov 25, 2026
9d2f560
merge: scoped subscription key note
alexasomba Nov 25, 2026
0b224d2
fix(flutterwave): send the numeric plan id to hosted checkout
alexasomba Nov 25, 2026
300b11f
docs(flutterwave): note abandoned subscription plans
alexasomba Nov 25, 2026
7e83604
fix(core): scope provider invoice ids by provider
alexasomba Nov 25, 2026
dcce582
fix(core): scope provider invoice ids by provider
alexasomba Nov 25, 2026
a1c6763
merge: scoped invoice ids
alexasomba Nov 25, 2026
1c3346d
docs(core): note the provider-scoped invoice key
alexasomba Nov 25, 2026
7c1ecbf
merge: scoped invoice key note
alexasomba Nov 25, 2026
d8912b9
fix(flutterwave): keep subscription checkout card-only
alexasomba Nov 25, 2026
e672fac
fix(flutterwave): name the plan after the subscription line
alexasomba Nov 25, 2026
54b67d5
docs(flutterwave): record the package-level plan probe
alexasomba Nov 25, 2026
7f5d332
feat(core): show the subscription provider in the admin list
alexasomba Nov 25, 2026
9bd5aae
feat(core): show the subscription provider in the admin list
alexasomba Nov 25, 2026
3d08d1a
merge: subscription provider column
alexasomba Nov 25, 2026
8134eb0
fix: resolve subscription renewals without a draft
alexasomba Nov 25, 2026
a1e0228
fix(core): ignore charges with no draft and no subscription
alexasomba Nov 25, 2026
a5e9643
merge: no-draft charge handling
alexasomba Nov 25, 2026
90b246f
fix(core): refuse subscription carts with vendor items
alexasomba Nov 25, 2026
b4bf286
fix(core): refuse subscription carts with vendor items
alexasomba Nov 25, 2026
f377abc
merge: subscription vendor guard
alexasomba Nov 25, 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
18 changes: 18 additions & 0 deletions .changeset/flutterwave-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@dashcommerce/flutterwave": minor
---

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

- Hosted checkout and on-page Flutterwave Inline (card, M-Pesa, mobile money) in NGN, USD, GBP, EUR, KES, GHS, ZAR, UGX, TZS, RWF, XOF, XAF, ZMW, MWK and EGP.
- Amounts convert at the boundary: core keeps minor units, Flutterwave's v3 API charges major units.
- Orders only from a signed `charge.completed`, confirmed with a live verify. `verif-hash` is checked in constant time against the secret hash; repeat and overlapping deliveries are deduplicated.
- Refunds by transaction id or `tx_ref`, guarded against duplicates on retry, with Flutterwave's refund webhook moving each refund to succeeded or failed.
- Split payments: core's exact per-vendor allocations map to `subaccounts` with `flat_subaccount`, for hosted and Inline. The subaccount default may be percentage or flat; the transaction override keeps the shares exact.
- In-admin vendor onboarding: list banks or mobile-money channels, verify the account name, create the collection subaccount, and store the masked result. Re-adding the same bank account returns the existing subaccount instead of failing.
- Cart discounts: `capabilities.coupons` is true; the discount is applied to the amount Flutterwave charges.
- Subscriptions through Flutterwave Payment Plans: one plan per checkout (the plan id is the subscription key), `payment_plan` on hosted and Inline, renewal invoices from the `plan` field on verify/webhook, and cancel/resume through the plan. Card-only; no trials, pause or in-place upgrades.
- Split reconciliation: parses `meta.split_settlement_info` and `app_fee` into core's `splitSettlement`, so the order records what each subaccount earned.
- "Test Flutterwave connection" checks the saved key in test or live mode with a read-only balances call.

Needs core 0.4.0 or later with the provider seams (public key, split allocations, payout onboarding, split settlement). Register with `import "@dashcommerce/flutterwave"`, add `api.flutterwave.com` to `allowedHosts`, and point the webhook at `…/checkout/webhook?provider=flutterwave`.
11 changes: 11 additions & 0 deletions .changeset/provider-payout-onboarding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@dashcommerce/core": minor
---

Provider-managed payout onboarding and richer vendor payout accounts.

- `VendorPaymentAccount` gains `accountName`, `verified`, `bankName`, `bankCode`, `country`, `maskedAccountNumber`, `metadata` and `createdAt`. `verified: false` means the provider created a usable account it has not verified; core still accepts it for splits.
- `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.
- Verification is optional. The form only requires it when the provider implements `resolvePayoutAccount`; otherwise the account is stored unverified. The country starts from the store's default currency, and `listPayoutBanks` may return mobile-money channels (e.g. M-PESA) as well as banks.
- The stored account keeps the resolved account name, bank and a masked account number; the full number is never persisted. Removing it detaches it from the vendor locally; the account at the provider is unchanged.
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.
13 changes: 13 additions & 0 deletions .changeset/provider-split-allocations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@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.
- `Vendor.stripeAccountId` is optional. A vendor paid through another provider omits it, so a shop without Stripe can create more than one vendor; a missing field is NULL, so the unique index does not clash.
- A cart-wide discount comes out of the platform remainder, matching the Connect plan; a discount larger than that remainder is refused with a readable 409 instead of silently reducing a vendor's payout.
- `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.
9 changes: 9 additions & 0 deletions .changeset/provider-split-refunds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@dashcommerce/core": minor
---

Make split refunds explicit.

- `PaymentProviderCapabilities.splitRefunds` lets a provider declare that its API cannot refund a split charge. Missing means yes, preserving Stripe Connect behaviour.
- `refundOrder` refuses a split order before calling a provider that declares `splitRefunds: false`, with a message pointing to the provider's dashboard.
- The order detail's **Split settlement** card warns that a refund comes from the platform balance and that vendor shares are not recovered automatically.
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.
12 changes: 12 additions & 0 deletions .changeset/provider-subscriptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@dashcommerce/core": minor
---

Add a provider-neutral subscription seam.

- `PaymentProvider` gains optional `getSubscription`, `cancelSubscription` and `resumeSubscription`. Stripe keeps its existing Billing path; providers that manage billing themselves can use these.
- `charge.succeeded` and `PaymentStatusResult` can carry `ProviderSubscriptionInfo`, so a provider can identify the subscription/plan behind a charge.
- A normalised `subscription.updated` event lets a provider report a cancellation or status change outside a charge; core updates the local row.
- New `subscriptions/provider.ts` stores a provider-managed subscription and its invoices in the existing collections. The provider id is part of the unique storage key for both subscriptions and invoices (`${providerId}:${id}`), so two providers cannot collide on a numeric plan or transaction id. The first charge creates an order and a local subscription; later charges are recorded as invoices and extend the period, not as new orders.
- `subscriptions/lifecycle.ts` dispatches cancel/resume to a provider-managed subscription. Pause and in-place plan changes are refused for providers that do not support them. The admin and customer portal hide pause and the Stripe billing portal for those subscriptions.
- Stripe's `stripeSubscriptionId`/`stripeInvoiceId` fields keep their names for compatibility; they now hold the provider's subscription/plan and invoice id.
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.

11 changes: 9 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ 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 or mobile-money channels, verifies the account name when the provider supports it, and creates the account; core stores the masked result on the vendor. A provider that creates an active but unverified account (Paystack's `is_verified: false`) should return `verified: false`; core still accepts it for splits.
- `capabilities.splitRefunds`: set `false` when the provider cannot refund a split charge. Core then refuses the refund before calling the provider and points the merchant to its dashboard. Missing means yes (Stripe Connect), though vendor shares are not clawed back.
- `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.
- `capabilities.subscriptions` plus optional `getSubscription`, `cancelSubscription` and `resumeSubscription`: core stores the provider's subscription/plan id from the first `charge.succeeded` that carries `subscription`, records later charges as invoices, and dispatches cancel/resume. Return `ProviderSubscriptionInfo`. A provider that cannot pause or change plans in place can omit those methods; core refuses the action with a readable error.
- `parseWebhookEvent` may return `subscription.updated` for a cancellation or status change outside a charge. Core updates the local row and does not create an order.
- Keep your own transaction fee on the platform (Paystack's `bearer_type: account`, Flutterwave's default) so each vendor receives exactly the share 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
Loading