Skip to content

Add hook to allow for custom webhook post-processing #4466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

daledupreez
Copy link
Contributor

Towards STRIPE-564

Changes proposed in this Pull Request:

This PR proposes the addition of a new wc_stripe_webhook_processed action that is triggered just after we process an inbound webhook from Stripe. This will make it easier for merchants and developers to include more details in WooCommerce based on the data from Stripe. The initial use case for this is to include more data for charges to allow for easier fraud detection while processing orders.

Testing instructions

TBD


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@daledupreez daledupreez self-assigned this Jul 7, 2025
Comment on lines +1358 to +1367
/**
* Fires after a webhook has been processed, but before we respond to Stripe.
* This allows for custom processing of the webhook after it has been processed.
*
* @since 9.7.0
*
* @param string $webhook_type The type of webhook that was processed.
* @param object $notification The webhook data sent from Stripe.
*/
do_action( 'wc_stripe_webhook_processed', (string) $notification->type, $notification );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like we should also include an order reference where possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payment_intent.succeeded and payment_intent.amount_capturable_updated events might be processed async

Without a major refactor, what we can do is exclude those events from this action, and do something similar to what was done for the do_action( 'wc_gateway_stripe_process_payment', $charge, $order ) call, which is called in both cases with the same params (the charge and the order):

do_action( 'wc_gateway_stripe_process_payment', $charge, $order );

do_action( 'wc_gateway_stripe_process_payment', $charge, $order );

Specifically for the request in STRIPE-564, the existing action might give them the info they want (it's called with the latest charge)

Copy link
Contributor

@malithsen malithsen Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to wrap the hook in a try/catch (and log the error on failure) so that it doesn't interrupt rest of the flow if something fails within the hook.

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.

3 participants