Created
April 10, 2024 08:38
-
-
Save mircobabini/419c99e95e33134acc716a5cd77c8e72 to your computer and use it in GitHub Desktop.
Define which Stripe webhook applications are permitted, then exclude any other webhook request coming through
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Define which Stripe webhook applications are permitted, then exclude any other webhook request coming through. | |
* | |
* This is expecially useful when you have multiple websites sharing the same Stripe account. | |
* Then, you gonna see multiple webhook requests coming from different applications. | |
* This snippet will allow you to filter out the ones you don't want to process. | |
*/ | |
// Detect Stripe webhook requests coming from an unexpected application and disable them. | |
add_action( 'pmpro_stripe_webhook_event_received', function ( $pmpro_stripe_event ) { | |
// Configuration. | |
$enabled_stripe_applications = [ | |
'ca_FTUyoenpif1m9qd9a5kEEFVcKpmMQs5m', | |
]; | |
if ( ! in_array( $pmpro_stripe_event->data->object->application, $enabled_stripe_applications ) ) { | |
add_action( 'pmpro_stripe_webhook_before_exit', function () { | |
global $logstr; | |
$logstr .= "Request coming from a different application."; | |
} ); | |
pmpro_stripeWebhookExit(); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment