Created
December 7, 2019 11:50
-
-
Save paulmiller3000/f9a8d5550bc781d69cc048b36bee5730 to your computer and use it in GitHub Desktop.
Extend WC_Stripe_Webhook_Handler to override the check_for_webhook function
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 | |
/** | |
* 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