Webhooks
A webhook is Stripe telling your site that something happened. Without one, your site only ever learns about payments the reader’s browser was present for.
That gap matters more than it sounds. Cancellations, failed renewals and successful renewals all happen at Stripe with nobody on your site. A site without a working webhook never records a renewal at all, and lags behind cancellations. Access does eventually catch up — the plugin refreshes a subscription from Stripe once its cached copy is an hour old — but a renewal that was never recorded stays unrecorded, and campaign totals never see it.
Setting it up
The plugin has an endpoint of its own on every site that takes payments. Its URL is your site address followed by its REST route:
https://example.com/wp-json/fabrica-monetization-kit/v1/stripe-webhook
In your Stripe dashboard, go to Developers → Webhooks, add an endpoint with that URL, and subscribe it to the events below. Stripe then shows a signing secret starting whsec_ — paste it into the Webhook secret field in the Gateways tab’s Webhook card, which also shows the URL and the exact event list. Test and live endpoints have different signing secrets, so change it whenever you switch between test and live keys.
The secret is what proves an incoming request really came from Stripe. Without it the plugin rejects everything, which is the correct thing to do but looks like nothing working.
When Stripe asks for a payload format, choose Snapshot. A thin payload names each object without including it, and the plugin refuses it: Stripe’s log shows 400, and an admin notice says why. Any API version Stripe offers works, because the plugin reads what it acts on back from Stripe at its own version.
With WooCommerce Stripe
If WooCommerce Stripe is installed and configured, the plugin creates its endpoint for you: press Set up endpoint in the Gateways tab’s Webhook card. There is nothing to add in Stripe and no secret to paste. The plugin uses WooCommerce Stripe’s keys to create an endpoint at its own URL, subscribed to one event, invoice.payment_succeeded, and keeps the signing secret Stripe returns. That event matters only for recurring contributions billed by Stripe, so the Gateways tab warns that the endpoint is missing only once a contribution block can sell a Stripe product; WooCommerce Subscriptions products renew through WooCommerce.
That endpoint sits alongside WooCommerce Stripe’s own, which WooCommerce Stripe creates and verifies itself and which hands this plugin the other events it needs, so leave that one as WooCommerce Stripe made it. WooCommerce Stripe subscribes its endpoint to its own fixed list of events, which leaves out invoice.payment_succeeded, and sets it back to that list whenever WooCommerce Stripe updates. The plugin’s endpoint keeps that event safe from those updates. Recurring contributions need it: without it no renewal is ever recorded.
Test and live mode need an endpoint each, since Stripe keeps them apart. The card says whether the mode WooCommerce Stripe is in has one; after switching mode, press the button again. Pressing it when one exists replaces it: the plugin creates a new endpoint, then deletes any other endpoint at its own URL on that Stripe account, so two never deliver at once. It never touches an endpoint at any other URL, such as WooCommerce Stripe’s or another site’s on the same account. If Stripe refuses, the tab shows Stripe’s message and nothing changes.
Events to subscribe to
Subscribe to all of these. Each one does a job, and a missing one fails quietly.
On a WooCommerce site this plugin’s endpoint acts on three events only — invoice.payment_succeeded, charge.refunded and payment_intent.succeeded — even where it holds the keys itself. Subscription changes and failed payments are WooCommerce’s to handle; sent to this endpoint they are answered 200 and ignored, so the Gateways tab lists only those three there.
On a WooCommerce Stripe site this plugin’s endpoint needs invoice.payment_succeeded only. charge.refunded and payment_intent.succeeded reach the plugin through WooCommerce Stripe’s endpoint, which subscribes them itself; sent to this one as well, they are answered 200 and ignored, so nothing is recorded twice.
Subscription lifecycle
| Event | Why it matters |
|---|---|
customer.subscription.created |
A new subscriber. |
customer.subscription.updated |
Upgrades, downgrades, cancel-at-period-end. |
customer.subscription.deleted |
The subscription has ended. Without this, access never expires. |
customer.subscription.paused |
Access should stop. |
customer.subscription.resumed |
Access should return. |
Billing
| Event | Why it matters |
|---|---|
invoice.payment_succeeded |
Records each renewal. Recurring donations depend on this. |
invoice.payment_failed |
An expired or declined card. Lets you prompt for new details. |
One-off payments
| Event | Why it matters |
|---|---|
payment_intent.succeeded |
Records a contribution whose donor closed the tab before returning to the site. Without it, Stripe takes the money and the site never hears about it. Abandoned article and author purchases are not recovered this way. |
Refunds
| Event | Why it matters |
|---|---|
charge.refunded |
Withdraws access on a full refund, and adjusts campaign totals. A partial refund adjusts the totals but leaves access in place. |
On a multisite network
A Stripe endpoint delivers to one URL, so every site on a network needs an endpoint of its own. Sites may share a Stripe account, but not an endpoint: a site without one never hears about its own renewals, refunds and cancellations, which go to whichever site is registered instead. The Gateways tab of each site shows its URL. Add one endpoint per site in Stripe, and paste each endpoint’s signing secret into that site’s Webhook secret field.
Checking it works
Check the delivery itself, in Stripe’s webhook page, which lists every attempt with its response. 200 is good. 400 almost always means the signing secret does not match; if an admin notice says the event arrived in thin format, the endpoint needs the Snapshot payload format instead. Repeated 500s mean something is failing on the site — the response body is a generic message, so turn on WP_DEBUG and read the [FMK] Webhook error: line in your PHP error log for the real one.
On a WooCommerce Stripe site, each endpoint’s page in Stripe lists its own deliveries: check that this plugin’s endpoint answers 200 to invoice.payment_succeeded, and that WooCommerce Stripe’s answers its own.
Cancelling a test subscription and reloading as that reader is a weaker test than it looks. On a WooCommerce site the cancellation is WooCommerce’s to handle, so it proves nothing about this plugin. And where the plugin owns the subscription, the hourly refresh removes access eventually even with the webhook broken — so if you do test this way, check within the hour.
A better test on a WooCommerce Stripe site is a refund: refund a contribution in Stripe and watch the campaign total drop. That exercises the whole path — WooCommerce Stripe receiving and verifying the event, and this plugin acting on it. A recurring contribution’s renewal is the test of this plugin’s own endpoint there.
Local development
Stripe cannot reach a site on your own machine. Use the Stripe CLI to forward events:
stripe listen --skip-verify --forward-to https://example.localhost/wp-json/fabrica-monetization-kit/v1/stripe-webhook
It prints its own signing secret when it starts. Put that in the Gateways tab’s Webhook secret field for as long as you are testing, and remember it is not the one your live site uses.
On a WooCommerce Stripe site there is no such field, and an endpoint the button creates at a .localhost address is one Stripe cannot reach. Store the CLI’s secret as the plugin’s test-mode endpoint with WP-CLI instead, with url exactly as the Webhook card shows it:
wp option update fabrica_monetization_kit_wc_stripe_webhook_endpoints --format=json \
'{"test":{"id":"stripe-cli","secret":"whsec_…","url":"https://example.localhost/wp-json/fabrica-monetization-kit/v1/stripe-webhook"}}'
Then forward to WooCommerce Stripe’s endpoint (https://example.localhost/?wc-api=wc_stripe) with a second stripe listen, and put the same secret in WooCommerce Stripe: the CLI signs every forward with one secret.
Handling events yourself
Every event this endpoint processes fires fabrica_monetization_kit_stripe_webhook, after the plugin has finished with it. The signature has already been checked, so the event can be trusted.
It does not fire for events the plugin skips — a duplicate delivery, or an event for a different Stripe account. On a WooCommerce Stripe site it fires for the three events the plugin acts on: invoice.payment_succeeded from this plugin’s endpoint, the other two by way of WooCommerce Stripe.
For the common cases there are friendlier actions: fabrica_monetization_kit_subscription_created, _subscription_renewed, _subscription_payment_failed, _subscription_deleted and _refund_processed. Each hands you the user ID directly instead of a Stripe customer to look up. See the hooks reference.