Repository navigation
feat(paystack): Paystack payment provider package - #85
Conversation
cavewebs
left a comment
There was a problem hiding this comment.
HMAC is done the way we asked: SHA-512 of the raw body, Web Crypto, constant-time compare, both Paystack-Signature (whsec_, 300 second window) and x-paystack-signature (sk_). When the current header and a whsec_ secret are present, a stale replay cannot sneak through on the legacy header. Amounts come from the cart, then /transaction/verify, then core's reconcile. ctx.http.fetch only, host api.paystack.co. No extra npm deps. Keeping this as its own package, not inside core, is right.
Please set providerEventId on refund events. You already have data.id. Empty string skips core's event dedup, and two refund.failed deliveries can both reverse the order (#82's pending check is not a lock). Something like refund.failed:19244346 is enough. For charge.success, core's unique index on the payment reference still stops a second order. Now that #81 drops the dedup row on ConfirmationFailure, you could also set charge.success:${reference} so a retry after a down verify still works, and two overlapping deliveries do not both run the handler.
README says the package is private and not published. package.json is public 0.0.0 with a minor changeset. If we merge as-is, the next release will publish @dashcommerce/paystack. Either add "private": true until you mean to ship it, or say in the README that 0.1.0 goes out with this core.
Webhook URL: tell merchants to append ?provider=paystack so a future header clash cannot depend on registry order. stripe-signature already wins for Stripe.
A PaymentProvider for Paystack on core's provider interface: card and M-Pesa through Paystack's hosted page or its Popup over the store's own checkout. - Orders come only from a signed charge.success, confirmed with /transaction/verify. Both signature schemes are checked with the key each is signed with: Paystack-Signature with a whsec_ secret (final when present, so its 300-second replay window holds) and x-paystack-signature with the sk_ key. In a real test-mode run Paystack sent only x-paystack-signature on an account with a whsec_ secret, so both matter. - Refunds by transaction reference, tagged with core's refundRequestId so a retry returns the existing refund instead of creating a second one; refund.* webhooks (which carry the refund id as a string) map to refund.updated. - A payment refunded in full at Paystack before its order exists is not confirmed, so a late webhook retry creates no order. Paystack reports reversed after partial refunds too, so the refunded total decides. - "Test Paystack connection" checks the saved key, test or live. - The Popup client (./checkout-client) loads js.paystack.co only when the customer presses Pay. Tested end to end in Paystack test mode: hosted and Popup, card and M-Pesa, declined cards, duplicate and stale webhooks, refunds that succeed and fail.
….4.0 - Set providerEventId on refund.* events (`<event>:<refund id>`), so two refund.failed deliveries reverse a refund once, and on charge.success (`charge.success:<reference>`), so overlapping deliveries run once. Core still releases the record when confirming with Paystack fails. - Peer @dashcommerce/core ^0.4.0 instead of workspace:*, which made changesets version this package 1.0.0. It now releases as 0.1.0. - README: needs core 0.4.0, install step, why ?provider=paystack, removed the pre-merge core requirements section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dc2f9e0 to
fadc0ef
Compare
|
Thanks for the review. All three points are in fadc0ef, on top of the branch rebased onto main (after #90). Event ids. Refund events now carry
The existing test where verify is down on the first delivery still passes: Tested by hand against Paystack test mode (24 Nov, this branch, EmDash 1.6, webhooks through a tunnel with
Publishing. It ships. The README says 0.1.0 goes out with core 0.4.0. I also changed the peer from Webhook URL. The setup step now says to include Also on the earlier PRs: noted on #84 that |
|
The follow-ups from this review round are up, so they're ready when you finish here. Each is small, tested and has a changeset. Any order, independent of #85:
After #85:
At the 0.4.0 / 0.1.0 release:
For discussion only, no action needed now:
|
|
Heads-up for the Paystack package, since subscriptions are the next item in #108: Core now has a provider-neutral subscription seam in #114 (open, independent). It adds optional #85 currently declares No action needed if it is out of scope — just flagging it so the seam is there when you get to the "Subscriptions with Paystack" item. Happy to share the Flutterwave adapter details if useful. |
|
@cavewebs the three points from your review are in fadc0ef (details in my comment above), so I'm re-requesting your review. CI is green and the branch merges cleanly with main. @alexasomba thanks for the pointer to #114. I'll keep subscriptions out of this PR so it stays small. Paystack Plans fit #114 well, as you say, so Paystack subscriptions will build on it once it lands. They're listed in #108. |
[FIK-57] feat(paystack): Paystack payment provider package (fork integration of upstream emdashCommerce#85)
Follow-up from your #84 review. Independent of #85 and of the other follow-ups; merge in any order. ## Change `client` in an on-page checkout result is sent to the browser as JSON by `create-session`. The README's provider-author list now says so, and that a provider must never put a secret key or webhook secret in it (Paystack sends only `{ accessCode }`). The same warning is on the `client` field in `types.ts`. Docs and a comment only, plus a patch changeset. No behaviour change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Found while testing #85. Independent of #85 and of the other follow-ups; merge in any order. ## Problem A skipped duplicate webhook logs `Stripe webhook deduped`, whichever provider sent it. A Paystack shop's log shows `Stripe webhook deduped { stripeEventId: 'charge.success:dc-…' }`. ## Change The log reads `Webhook deduped { providerId, eventId, type }`. If anyone filters logs on the old `stripeEventId` field, it is now `eventId`. The storage collection and its `stripeEventId` field are unchanged, since renaming them would need a migration. ## Tested The existing "skips an exact repeat" test now also checks the log line and provider. It fails without the change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Follow-up from your #81 review. Independent of #85 and of the other follow-ups; merge in any order. ## Problem The settings API checks only that `paymentProvider` looks like an id. A typo (`paystak`) or a provider whose package isn't imported on the server saves fine, then checkout fails. ## Change `admin/settings` and `admin/settings/validate` check the value against the provider registry. An unregistered id gets a 400 under `errors.paymentProvider`: > paymentProvider "paystak" is not a registered payment provider. Registered: stripe, paystack. Import the provider's package in a server module first. The schema module still only checks the shape, so the admin bundle doesn't import the registry. Saves that don't include `paymentProvider` are unaffected. ## Tested Two route tests in `provider-credentials-settings.test.ts`: the save refuses an unregistered id and stores nothing, a registered one still saves, and the single-field validator flags it too. Both fail without the change. Core: 317 pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
cavewebs
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. The refund providerEventId is in place, and the publish metadata looks right: 0.1.0, public, with a ^0.4.0 peer on core. I'll merge this now.
Part of the Flutterwave set described in #97. **Item 2** — a generic core seam, independent of #85 (Paystack) and #98 (the Flutterwave package). No Flutterwave code in core. ## Why Flutterwave Inline, its on-page checkout, is a browser SDK initialised with the account's **public** key (`FLWPUBK-…`). Core's provider settings stored only `secretKey` and `webhookSecret`, and a provider has no KV access, so the server could not hand the browser client the key it needs. The shortcut — deriving the public key from the secret key — is not available. I checked a real test pair: `FLWPUBK_TEST-991d…` and `FLWSECK_TEST-03d5…` have different hash segments. ## What - `PaymentProviderCredentials.publicKey` and `credentialFields.publicKey` (label, prefixes, help). - `settings:<id>PublicKey` in the settings schema, `providerCredentialSetting` and `GET admin/settings` `_providers`, validated against the prefixes the provider declares and masked like the other credentials. - A third field in Settings → Payment provider, rendered **only** for a provider that declares one. - `loadPaymentProviderCredentials` returns `publicKey` when set. ## What does not change - Stripe's fields, keys and behaviour. - Providers that do not declare a public key: their settings row is byte-for-byte the same, and a `publicKey` value is refused for them (so a typo cannot save a key nothing reads). - The secret key and webhook secret are still offered for every provider, as before. ## Tests - `provider-credentials-settings.test.ts`: saves and loads the public key, validates its prefix, refuses one for a provider that does not declare it, never returns the value (only set/hint), and omits the row entirely for such a provider. - 12 tests in that file, 58 across the provider/credentials/webhook-header files, `tsc --noEmit` clean. - Changeset: minor for `@dashcommerce/core`. ## Next Item 3 is [#100](#100): the provider declares the field, returns `on_page` with `{ publicKey, txRef, amount, currency, customer… }`, and ships a `./checkout-client` that loads `checkout.flutterwave.com/v3.js` only when the customer presses Pay. The split seams are [#101](#101) (core) and [#102](#102) (Flutterwave). All are open.
Part of the Paystack set described in #76. Builds on #84.
What
packages/paystack: aPaymentProviderfor Paystack on core's provider interface. It covers card and M-Pesa, through Paystack's hosted page or its Popup over the store's checkout, in KES, NGN, GHS, ZAR and USD. It registers itself onimport "@dashcommerce/paystack". The README covers setup:allowedHosts: ["api.paystack.co"], keys, webhook URL and the Popup client.How it behaves
charge.success, confirmed with/transaction/verifybefore core writes the order. Paystack sends nocharge.failed, so a failed or abandoned payment leaves no order.Paystack-Signaturewith awhsec_secret. When it's present, it alone decides, so its 300-second replay window can't be sidestepped by the older header sent with it.x-paystack-signature, with ansk_key saved in either field.x-paystack-signature, on an account with awhsec_secret, so both paths matter.refundRequestId, so a retry returns the existing refund instead of creating a second one. Paystack itself accepts identical duplicates.refund.*webhooks map torefund.updated. Real ones carry the refundidas a string; Paystack's docs don't show it.reversedafter partial refunds too, so for areversedorreversal-pendingpayment the package adds up its refunds. One refunded in full is not confirmed, so a latecharge.successretry creates no order; a partly refunded one is../checkout-clientloadsjs.paystack.coonly when the customer presses Pay.Package
publishConfig.access: public, author "DashCommerce contributors". Minor changeset takes it to 0.1.0.bun.lockgains only the new workspace entry.Tests
Paystack-Signaturethat must not fall back.End to end in Paystack test mode (20 Nov 2026)
whsec_saved, onlyx-paystack-signaturesentduplicate, one order / 400 outside the windowrefund.pending→refund.processed(succeeded) andrefund.failed(failed)Screenshots