Repository navigation
Description
Summary
PR #40 merged the PaymentProvider seam and listed what it deferred. We've built a real second gateway on it, Paystack, for card and M-Pesa in Kenya, and tested it end to end in Paystack's test mode against real deliveries from Paystack.
A released core can't run it yet. This issue lists the core changes it needs in one place, with the PRs that implement them, so you can review the shape once. Each PR is small, has a changeset, and passes CI on its own.
The PRs, in merge order:
| # | PR | What it does |
|---|---|---|
| 1 | #80 fix(core): admin follows EmDash's light and dark theme | Fixes #44. Independent; the Settings screens below use its theme module |
| 2 | #81 feat(core): let non-Stripe payment providers run on a live site | Items 1–5 below. Generic, no Paystack code in core |
| 3 | #82 feat(core): a refund that fails at the provider no longer counts | Item 3b. Builds on 2 |
| 4 | #83 feat(core,starter): checkout follows the active payment provider | Item 6. Builds on 2 |
| 5 | #84 feat(core): on-page checkout for any payment provider | Item 7. Builds on 4; Paystack's Popup needs it |
| 6 | #85 feat(paystack): Paystack payment provider package | packages/paystack, registers itself on import. Builds on 5 |
Each PR is based on the one it builds on, so once that one merges, its diff shows only its own change.
Also sent, unrelated to Paystack (found during the same test run, each independent):
- fix(core): only offer shipping methods priced in the cart's currency #77 fix(core): only offer shipping methods priced in the cart's currency: a USD-priced flat rate offered to a KES cart crashed
POST /cart/shipping-methodwith a 500. - fix(starter): keep the cart drawer closed when continuing to payment #78 fix(starter): keep the cart drawer closed when continuing to payment
- fix(starter): pre-bundle the Stripe packages in dev #79 fix(starter): pre-bundle the Stripe packages in dev: stops "Invalid hook call" in an open admin tab after the first
/checkoutvisit.
How this maps to PR #40's deferred list
| Deferred in #40 | Here |
|---|---|
Settings UI for settings:paymentProvider |
Item 2: provider cards plus per-provider credentials |
| Per-provider webhook URL path | Not needed. Item 4 (all headers plus credentials) covers Paystack on the existing URL |
| POS / async polling | Not in this set. Paystack's hosted page and Popup work without it |
| Publishing to npm | Question below |
The core changes
1. Providers can add outbound hosts
dashcommerce() hard-codes Stripe's hosts, and on EmDash 1.5 ctx.http.fetch("https://api.paystack.co/…") throws. New option, added to Stripe's hosts so existing Stripe webhooks and refunds keep working after a switch:
dashcommerce({ allowedHosts: ["api.paystack.co"] });Declaring hosts on the provider object would be neater, but the descriptor is built at config time, before a gateway package registers at runtime.
2. Per-provider credentials and a provider picker
Core already reads settings:<id>SecretKey and settings:<id>WebhookSecret, but the settings API refused to save them. Now it accepts them for every registered provider, checked against the prefixes the provider declares in credentialFields, and stored and masked like Stripe's. Settings shows one card per registered provider, with nothing selected on a new store, and a "Test connection" button for providers that declare checkConnection. Stripe's fields and defaults are unchanged.
3. refund.updated
Paystack refunds start pending and settle later: minutes in test mode, days live. A new normalised event moves the matching refund row to succeeded or failed.
3b. A failed refund stops counting against the order
Core counts a refund against the order as soon as it's requested. When the provider later fails it (Paystack sends refund.failed), or fails it straight away, the order still showed the money as returned and restocked items stayed in stock. Now a failed refund is reversed on the order: refunded total, payment status and order status are worked out again, and restocked items are taken back (ledger reason refund_failed). With no refund left counting, the order returns to the status it had before its first refund. The failed refund stays on the order page, marked failed, and is logged. A refund failed at creation changes nothing on the order and sends no refund email.
4. verifyWebhook gets every header and the provider's credentials
Paystack documents two signatures: Paystack-Signature (HMAC over t.body with a whsec_ secret, 300-second window) and the older x-paystack-signature (HMAC of the body with the sk_ key). Core passed only one header. VerifyWebhookInput now also carries headers and credentials, both optional, so existing providers are untouched. Providers can declare webhookHeaders; stripe-signature stays Stripe's.
The credentials matter in practice. In our test run Paystack sent only x-paystack-signature, on an account that had a whsec_ secret. A store set up with that whsec_ refused every webhook until the package could check the old header with the saved sk_ key. When Paystack-Signature is present, it alone decides, so its replay window can't be sidestepped.
5. One narrow exception to webhook dedup
The route records the event id before handlers run and keeps it on failure; we keep that rule. The exception: when the only failure was confirming the payment with the provider (getPaymentStatus, or Stripe's PaymentIntent retrieve on checkout.session.completed), the dedup row is removed so the provider's retry creates the order. Before, the retry got 200 {duplicate: true} and a paid order was never created. This affects Stripe too. Other failures and exact repeats stay deduplicated; tests cover both.
6. Checkout follows the active provider
The starter's checkout refused stores without Stripe keys and said "Pay with Stripe". Paystack's page collects neither email nor address, so a payment either failed to start or never became an order ("Session missing address"). Providers now declare collectsCustomerDetails (Stripe does). For those that don't, create-session needs an email and address first (409 customer_details_required), and the form collects them through cart/contact. The form also shows readable errors instead of [object Object], which Stripe stores saw too. Stripe pages are unchanged.
7. On-page checkout for any provider
Providers declare checkoutStyles. With checkout set to embedded, create-session returns { kind: "on_page", client, returnUrl } for a provider that supports it, and the form opens the provider's browser client. The client's callbacks only move the customer; orders still come only from the signed webhook. Stripe Elements is unchanged.
Where the package lives
@dashcommerce/paystack sits in this monorepo beside core and Lite, publishable like core, so it is versioned and released with the provider interface it depends on, and its tests run against core's real routes in the same CI. We maintain its code.
Evidence: end to end in Paystack test mode (20 Nov 2026)
Run on the starter with all the PRs above merged together; KES throughout; test keys only.
| Area | Result |
|---|---|
| Stripe, hosted and on-page | Paid orders; checkout.session.completed / payment_intent.succeeded answered 200 |
| Paystack hosted, M-Pesa | Paid order |
| Paystack Popup, M-Pesa and card | Paid orders. M-Pesa is offered in the Popup. Nothing loads from js.paystack.co until Pay |
| Popup closed without paying | "Payment not completed. You can try again."; no order |
| Declined card | No order; customer can retry |
| Real Paystack deliveries | Only x-paystack-signature arrived. Refused before the item 4 fix (no order); after it, 200 and an order. Paystack's retry of the refused delivery created that order |
| Same webhook again / 400 s old | 200 duplicate, one order / 400 outside the window |
| Refunds | Partial and full; real refund.pending → refund.processed (succeeded). Refund webhooks carry the refund id as a string; Paystack's docs don't show one |
| Refund Paystack fails | Real refund.failed → refund marked failed, and the order back to paid with nothing counted as refunded |
| Payment refunded in full before its order exists | Paystack's verify says reversed; the package sees the refunds cover the whole amount and doesn't confirm it, so a late retry creates no order. A partly refunded payment is still confirmed |
| Double-clicked refund | Second refused, "already in progress"; one refund |
| Refund a Stripe order after switching to Paystack | Succeeds; old Stripe webhooks still verify |
| Shipping method priced in another currency | Not offered; the customer sees "We don't ship to that location yet." instead of a 500 |
| Admin, light and dark | Readable throughout |
Activity
feat(core): let non-Stripe payment providers run on a live site (#81)
feat(core): a refund that fails at the provider no longer counts (#82)
feat(core,starter): checkout follows the active payment provider (#83)
feat(core): on-page checkout for any payment provider (#84)
alexasomba commentedon Nov 24, 2026
@moset15, great work. mind bringing it to some parity with Stripe at least. I am not sure if Multi Vendor, using the Paystack split payment feature is included, as the issue did not specify (to mention one that comes to mind)
moset15 commentedon Nov 24, 2026
Thanks. You're right that #76 didn't spell this out: multi-vendor isn't in #85. Here is where Paystack stands against what DashCommerce does with Stripe, and the order I'd close the gaps.
refund.*webhooksOrder:
coupons, with a test that a discounted cart pays the right amount. One PR on top of feat(paystack): Paystack payment provider package #85.The full order, including disputes and in-person payments with Paystack terminals, is in #108.