DonationWebhookSecrets
\Benecaster\Payment\DonationWebhookSecrets
Manages encrypted storage of per-platform webhook verification credentials for non-Stripe Listener Support donation platforms (Ko-fi, PayPal, Buy Me a Coffee). Each secret is encrypted at rest with the same libsodium encryption as Stripe API keys — plaintext is never written to wp_options. Unsupported platform slugs are hard-rejected by all methods.
Platform slugs are normalized before storage and lookup — Ko-Fi, ko_fi, kofi, and KoFi all resolve to the canonical kofi slug.
Constructor Dependencies
| Type | Description |
|---|---|
\Benecaster\Payment\Crypto |
Encrypts each secret before it is written and decrypts on read. The same libsodium layer used for Stripe API keys. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
__construct( Crypto $crypto ) |
Public | — | Injects the encryption layer. In normal plugin flow this is resolved via the service container — instantiate directly only in tests. |
get( string $platform ): string |
Public | — | Returns the decrypted secret for the given platform slug. Returns an empty string when no secret is saved. Throws InvalidArgumentException for unsupported platform slugs. |
save( string $platform, string $secret ): void |
Public | — | Encrypts and persists the secret for the given platform. Passing a whitespace-only string clears the stored credential. Throws InvalidArgumentException for unsupported platform slugs. |
is_set( string $platform ): bool |
Public | — | Returns true when a non-empty secret is saved for the platform. Safe to call without instantiating the full object — use as a gate before calling get(). Throws InvalidArgumentException for unsupported platform slugs. |
static option_for( string $platform ): string |
Public | — | The wp_options name a platform's secret is stored under, or an empty string for an unknown platform. It exists so the credential migration can tell "never set" apart from "stored but no longer readable", which get() reports the same way. Do not use it to read or write a secret; use get() and save(), which handle the encryption. |
static supported_platforms(): array |
Public | — | Returns the list of canonical platform slugs supported by this class: ['kofi', 'paypal', 'bmac']. |
static is_supported( string $platform ): bool |
Public | — | Returns true when the given slug (after normalization) is a supported platform. Use this to guard before calling save() or get() when the platform slug comes from user input. |
Constants
| Name | Value | Description |
|---|---|---|
PLATFORM_KOFI |
'kofi' |
|
PLATFORM_PAYPAL |
'paypal' |
|
PLATFORM_BMAC |
'bmac' |
Notes
Secrets are write-only from the admin's point of view — the settings screen shows whether a secret is set, never the value. Read paths decrypt in memory for signature verification only.
Because plaintext is never stored, a lost secret cannot be recovered from Benecaster; it has to be re-copied from the donation platform.