Skip to content

feat(core): refunds, payment settings and vendor payouts for admins only - #155

Open
moset15 wants to merge 1 commit into
emdashCommerce:mainfrom
FIKANOVA:feat/admin-only-money
Open

moset15 wants to merge 1 commit into
emdashCommerce:mainfrom
FIKANOVA:feat/admin-only-money

Conversation

@moset15

@moset15 moset15 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

What and why

DashCommerce's admin routes don't check who is calling. EmDash's default plugins:manage permission keeps them to Admins today, but once the shop admin is opened to Editors (a route declaring a lower permission, so Editors can manage orders or reviews, say), every Editor could also refund orders, change payment keys and set up vendor payouts.

This keeps money admin-only, using EmDash's roles (ctx.user.role, Admin = 50). It's the "Refunds and payment settings for admins only" item on #108.

Behaviour

These now answer 403 with a plain message for anyone who isn't an Admin, including a call with no signed-in user:

  • Refunds: admin/orders/refund.
  • Payment settings: changing the provider, checkout mode, Stripe keys, provider keys or webhook secrets through admin/settings. Other settings stay open to whoever can open the admin. An untouched masked secret counts as no change.
  • Payment connection checks: admin/stripe/ping, admin/payments/check-connection.
  • Subscriptions: cancel and resume (admin/subscriptions/action).
  • Vendor payouts: creating or editing a vendor, onboarding links, payout-account look-up and creation.

Reading stays open: an Editor still sees orders, subscriptions, vendors and settings.

In the admin: the order page shows an Editor "Only an admin can issue refunds" instead of the refund form, and the Settings page greys out the payment cards (_canManagePayments on the settings response tells it).

Changes

  • packages/core/src/routes/admin-api.ts: isAdmin, adminOnly and isPaymentSetting helpers; the checks above; canRefund on the order detail.
  • packages/core/src/admin/pages/OrderDetailPage.tsx, SettingsPage.tsx: the Editor view.
  • packages/core/README.md: a short section on who can do what.
  • packages/core/test/helpers/route-harness.ts: ADMIN_USER and EDITOR_USER.
  • Changeset: patch for @dashcommerce/core.

Tests

  • packages/core/test/admin-only-money.test.ts (new): each money route refuses an Editor and a call with no user, and moves no money or saves nothing; an Admin gets through; an Editor still reads the order and changes non-payment settings.
  • Existing tests that call these routes now call them as an Admin (provider-*, refund-idempotency, vendor-payment-accounts, and the Paystack and Flutterwave core-integration tests).

The new tests fail without the change. Suites run locally: core 469, paystack 106, flutterwave 137, all passing. tsc --noEmit and the build are clean; bun.lock is unchanged. It also passes merged with #152, #153 and #154.

Also tested by hand on a running shop (EmDash 1.6, Paystack test mode, KES):

Check Admin Editor
Order page refund form; a KES 5.00 refund went to Paystack and shows in refund history "Only an admin can issue refunds" in place of the form; refund history still visible
admin/orders/refund 200 403 ADMIN_ONLY
Settings page payment cards editable payment cards greyed out with "Admins only"; Store settings still save (200)
admin/settings with checkoutMode covered by tests 403
admin/payments/check-connection covered by tests 403
admin/subscriptions/action covered by tests 403
Vendor create, payout account covered by tests 403; the vendor list still loads

With EmDash's default plugins:manage, an Editor gets EmDash's own 403 before any of this runs. To reach these checks I lowered that default to content:read locally for the Editor run, then put it back.

Review points

  • Why ctx.user.role and not a permission? EmDash exposes the role on the route context; Admin (50) is the one role every site has. If you'd rather have a DashCommerce permission that sites can grant, the checks sit in one helper, isAdmin.
  • Why leave reads open? Editors managing orders need to see them; only actions that move money or change where it goes are locked.

Any user who could open the shop admin could refund an order or change
payment keys. The refund route, payment-setting changes, payment
connection checks, subscription cancel and resume, and vendor payout
changes now check `ctx.user.role` and answer 403 for anyone who isn't an
EmDash Admin. The admin hides the refund form and greys out the payment
cards for non-admins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moset15
moset15 force-pushed the feat/admin-only-money branch from 1310276 to 3b1e34f Compare December 6, 2026 11:06
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