Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulmiller3000/f9a8d5550bc781d69cc048b36bee5730 to your computer and use it in GitHub Desktop.
Save paulmiller3000/f9a8d5550bc781d69cc048b36bee5730 to your computer and use it in GitHub Desktop.
Extend WC_Stripe_Webhook_Handler to override the check_for_webhook function
<?php
/**
* Extend WC_Stripe_Webhook_Handler and override the check_for_webhook function
*
*/
if (!class_exists('My_Stripe_Webhook_Handler')) :
class My_Stripe_Webhook_Handler extends WC_Stripe_Webhook_Handler {
public function __construct() {
parent::__construct();
// child filter
add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'), 9);
}
public function check_for_webhook() {
error_log('DEBUG WOO-HOO!!!! Entered child version. Modify however you like.');
if (('POST' !== $_SERVER['REQUEST_METHOD'])
|| !isset($_GET['wc-api'])
|| ('wc_stripe' !== $_GET['wc-api'])
) {
return;
}
$request_body = file_get_contents('php://input');
$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
// Validate it to make sure it is legit.
if ($this->is_valid_request($request_headers, $request_body)) {
error_log('DEBUG: TO-DO Now examine the request_body');
$this->process_webhook($request_body);
status_header(200);
exit;
} else {
WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
status_header(400);
exit;
}
}
}
endif; // class_exists check
new My_Stripe_Webhook_Handler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment