Skip to content

Paystack as a second gateway: what core needs, sent as one reviewed set #76

Open

Description

@moset15

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):

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

  1. alexasomba commented on Nov 24, 2026

    @alexasomba

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

  2. moset15 commented on Nov 24, 2026

    @moset15
    ContributorAuthor

    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.

    Stripe feature in DashCommerce Paystack in #85 Paystack's equivalent
    Hosted and on-page checkout yes (hosted page, Popup)
    Refunds, with refund.* webhooks yes
    Cart coupons no: checkout answers 409 none needed: core already sends Paystack the discounted total
    Multi-vendor (Connect) no: 409 Split payments: each vendor gets a Paystack subaccount (bank or M-PESA), and one payment is divided between the shop and its vendors, with the shop paying Paystack's fee as with Stripe Connect
    Vendor payout onboarding no create a subaccount from the vendor's bank or M-Pesa details
    Subscriptions, dunning, customer portal no: 409 Plans and Subscriptions, with Paystack's manage-subscription link
    Stripe Tax not applicable flat and table tax already work with any provider

    Order:

    1. Coupons. Small: Paystack is charged the cart total after the discount, so the package only has to declare coupons, with a test that a discounted cart pays the right amount. One PR on top of feat(paystack): Paystack payment provider package #85.
    2. Multi-vendor. Rather than add a second split seam to core, Paystack splits will build on the generic one in feat(core): split payments across vendor payout accounts #101 (onboarding on feat(core): provider-managed payout account onboarding #103, settlement records on feat(core): split settlement and refunds #105), so Flutterwave and Paystack share it. I've checked feat(core): split payments across vendor payout accounts #101, feat(core): provider-managed payout account onboarding #103 and feat(core): split settlement and refunds #105 against Paystack's split API and left notes on each: the seam fits Paystack, with two small onboarding points on feat(core): provider-managed payout account onboarding #103.
    3. Subscriptions. The largest piece: core's subscription flow is built on Stripe Billing today. I'll open it as its own proposal before writing code.

    The full order, including disputes and in-person payments with Paystack terminals, is in #108.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions