Skip to content

feat: support Paystack restricted keys and webhook signing secrets - #26

Draft
jules-paystack wants to merge 19 commits into
mainfrom
feat/restricted-keys
Draft

jules-paystack wants to merge 19 commits into
mainfrom
feat/restricted-keys

Conversation

@jules-paystack

@jules-paystack jules-paystack commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds Paystack restricted-key support to the Gravity Forms add-on, following the pattern in the Shopify, Ecwid and BigCommerce plugins. Releases as 2.0.10.

Draft: waiting on (1) a test with real Paystack test keys and (2) the merchant documentation.

What changes for merchants

  • Restricted keys only. Each mode has a Restricted Key field (rk_test_… / rk_live_…), and new or changed keys must be restricted keys. The settings page no longer mentions secret keys.
  • One mode at a time. Only the selected mode's fields are shown (Gravity Forms 2.5 live dependency, so the minimum is now Gravity Forms 2.5). Both modes' credentials are still validated on every save, because Gravity Forms skips validation of hidden fields but still saves their values. An error in the hidden mode is also flagged next to Mode.
  • No public key. The public key fields are removed. Payments never used them, and the usage-tracking ping no longer sends one.
    • When a restricted key is saved, it's checked with Paystack. It needs Transactions: read and write, and keys with money-moving permissions (transfers, refunds, settlements, payouts and similar) are refused.
    • Plans: write is also checked when a subscription feed uses the key.
    • The check runs on every save, not only when the key changes, because permissions can change in the Dashboard while the key stays the same. If Paystack can't be reached, a key that was already accepted stays in use.
  • Webhook signing secret. Each mode gets a new signing secret field (whsec_…), and a restricted key requires it. Once a mode has a signing secret, only Paystack-Signature webhooks are accepted for that mode.
  • Payment confirmation. A charge.success webhook is now confirmed with Paystack (transaction/verify) before an entry is marked paid. If that check can't reach Paystack, the plugin returns HTTP 500 so Paystack retries.
  • Logs and inputs. Keys and signing secrets are hidden in logs, and the key fields are now password inputs.
  • URL override removed. The admin-only ?secret= / ?public= URL override for API keys has been removed.

Existing merchants need to do nothing. Saved settings carry over unchanged. A site on an sk_ key keeps working, and can re-save its settings without a signing secret or a permission check. Only when the key is replaced must the new key be a restricted key with its signing secret; there is no switching back.

Commits

  • Payment confirmation: fix: confirm charge.success with Paystack before completing a payment
  • Keys:
    • feat: add key shape, save rules and log redaction for restricted keys
    • feat: check a restricted key's permissions with Paystack before saving it (ported from the BigCommerce validator)
  • Webhooks: feat: verify webhooks with the Paystack signing secret
  • Settings: feat: accept restricted keys and webhook signing secrets in settings
  • Logs: feat: hide keys in logs and log restricted-key scope refusals
  • Docs: docs: explain restricted keys and webhook signing secrets
  • Review follow-ups:
    • fixes from two review passes and the test pass
    • test coverage
    • a behaviour-preserving cleanup
  • Release: chore: release 2.0.10 (version, changelog, upgrade notice)
  • Settings: feat: accept only restricted keys for new keys and show one mode at a time
  • Settings: feat: re-check a saved restricted key's permissions on every save

How it was checked

  • Unit tests: php tests/run.php passes all 406 checks on PHP 8.5 and 7.2. A mutation run showed the tests catch 188 of 200 deliberate breakages.
  • WordPress in Docker (PHP 8.2): the plugin was loaded in WordPress against a stand-in Gravity Forms core and a stand-in Paystack API. No PHP warnings were logged.
    • Settings page: keys missing Transactions: write, keys with Transfers, and unknown keys are each refused with their specific message, and nothing is saved. A correctly scoped key saves.
    • Webhooks:
      • Accepted: a signed charge.success marks the entry Paid, a repeat changes nothing, and a second v1 signature (rotation) is accepted.
      • Rejected: a stale timestamp, a tampered body, unsigned requests, and requests signed only with the old-style header.
      • Payment check: a Paystack outage returns 500, and a mismatched or failed transaction leaves the entry unpaid.
    • Upgrade path: a site configured as 2.0.9 left it (sk_ key, no signing secret) still completes payments and re-saves its settings with no extra calls. Switching it to a restricted key and signing secret then works.

Before this leaves draft

  • Test with real Paystack test keys: save a restricted key and signing secret, take a test payment, and confirm the entry is marked Paid. The debug log should show Webhook verified … sig=whsec result=valid.
  • On a real Gravity Forms 2.5+ install, confirm a refused save keeps the previously stored settings.
  • Merchant setup documentation: updated with the new settings page and screenshots, waiting for review.
  • Set the changelog date to the release day.

Not in this PR

  • Stored keys are not encrypted.
  • A key's permissions are not re-checked after it's saved.
  • Webhooks are not de-duplicated within the 5-minute signature window. Repeats are harmless because completing a payment twice changes nothing.

Risks

  • charge.success now makes one extra Paystack API call per payment.
  • If a signing secret is added on an sk_ site, it becomes the only accepted webhook signature for that mode. A wrong secret stops webhooks until it's fixed.

🤖 Generated with Claude Code

jules-paystack and others added 19 commits November 18, 2026 20:41
The webhook payload's amount and currency are no longer trusted on their own;
the transaction is fetched from transaction/verify and its status, id, amount
and currency must match before the entry is completed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GF_Paystack_Keys classifies sk_/rk_ keys, decides what a settings save needs
(probe, wrong field, bad shape, missing or duplicated signing secret), exposes
the gform_paystack_restricted_keys_enabled switch and redacts keys and
whsec_ secrets from log text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g it

GF_Paystack_Restricted_Key probes the key in sequence (ported from the
BigCommerce validator, without the ident call): it must hold Transactions
read and write and none of the money-moving scopes. Anything other than an
exact scope refusal fails closed. probe_plans() checks Plans: write for
subscription feeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a mode has a whsec_ signing secret, Paystack-Signature (HMAC-SHA512 of
"<t>.<body>", 5-minute window, any v1 entry) decides alone, so a delivery
can't be downgraded to the untimed legacy header. Without one, the legacy
X-Paystack-Signature check runs only for a stored sk_; a restricted key is
never used as an HMAC key. Keys for verification are read straight from
settings, and an event with no data.domain is verified under each configured
mode instead of the global one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every plugin log line goes through GF_Paystack_Keys::redact(), and an
API call refused for a missing restricted-key scope logs
"rk scope denied method=… path=…" so support can see which permission is
missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Test/Live secret key fields accept sk_ or rk_ keys and become password
inputs, with new Test/Live webhook signing secret fields beside them. Saving
a changed restricted key checks its permissions with Paystack, a restricted
key requires its mode's signing secret, and credential fields are stored
trimmed. Saving a subscription feed whose mode uses a restricted key checks
Plans: write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Redaction no longer stops at characters a restricted key may contain, a
filter can't smuggle a second Authorization header into a probe, test and
live probes share one time budget per request, and scope labels live in the
probe table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A verify call that throws during charge.success answers 500 so Paystack
  retries; both branches now require the verified id and reference to match.
- An event without data.domain only tries modes with a signing secret, and
  otherwise keeps the original api_mode fallback; failures log every attempt.
- The admin ?secret=/?public= URL override no longer reaches Paystack calls.
- Signing-secret fields validate themselves; switching a mode to a restricted
  key also checks Plans: write when that mode has active subscription feeds;
  subscription feeds are only re-probed when their type or mode changes, and
  keep Gravity Forms' own transaction type check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pins the full probe table, every classifier status, transport failures,
redaction of every error_log line, per-field validation callbacks and the
regressions fixed in the diff review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A domainless webhook also tries the site's API mode after the signing-secret
  modes, so an sk merchant with a secret in only one mode keeps webhooks.
- Restricted-key characters and the log redactor's stop characters no longer
  overlap; a failed verify answers with a fixed message.
- The plans check covers inactive subscription feeds, resolves feeds without a
  mode like checkout does, and its settings-page copy fits that page.
- The probe time budget renews in long-lived processes; header names are
  trimmed before the Authorization strip; chained feed callbacks get all args.
- Changelog notes the removed ?secret=/?public= override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lpers

No behaviour change: shared helpers for the other mode, save errors and
stored settings; webhook candidate modes in their own method; one request
default and verdict builder in the probe class; a cheaper log redactor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… time

New or changed keys must be rk_ keys; an sk_ key saved by an earlier
version keeps working until it is replaced. The public key fields are
gone (payments never used them). Test and Live fields show only for the
selected mode, so credentials are validated from the Mode field for both
modes: Gravity Forms skips validation of fields a dependency hides but
still saves their values. Requires Gravity Forms 2.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Permissions can change in the Paystack Dashboard without the key
changing, so a kept rk_ key is probed again whenever settings are saved.
A definite refusal blocks the save; an unreachable Paystack does not
block a key that was already accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gravity Forms 2.5+ takes the settings field object by reference in
set_field_error(). Passing an array crashed every refused save with a
fatal error on PHP 8, including the existing custom-metadata checks on
feeds. Errors now go through set_setting_error(), which looks the field
up through the settings renderer and falls back to the field being
validated. The test stubs now follow the same contract.

Found by testing against real Gravity Forms 2.7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Credential errors had no fallback: if Gravity Forms couldn't find the
named field, the error was lost and a refused key would save. While
validate_credentials() runs, errors now fall back to the Mode field, and
an error with nowhere to go is logged. Scope labels in key errors are
escaped, since Gravity Forms prints field errors as HTML.

Tests: the stub set_field_error() now throws on anything Gravity Forms
would ignore, the fixture renderer only finds the add-on's defined
fields, and the fallback paths are covered.

Note on f37a492: the array argument crashed on every supported PHP
version (7.2+), not only PHP 8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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