Skip to content
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

Report test webhook errors in the live environment as warnings #3696

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.1.0 - xxxx-xx-xx =
* Fix - Report test webhook errors in the production environment at debug level
* Fix - Prevents duplicated credit cards to be added to the customer's account through the My Account page, the shortcode checkout and the block checkout.
* Fix - Return to the correct page when redirect-based payment method fails.
* Fix - Show default recipient for Payment Authentication Requested email.
Expand Down
13 changes: 11 additions & 2 deletions includes/class-wc-stripe-webhook-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,17 @@ public function check_for_webhook() {
status_header( 200 );
exit;
} else {
WC_Stripe_Logger::error( 'Webhook failed validation. Reason: ' . $validation_result );
WC_Stripe_Logger::error( 'Webhook body: ' . print_r( $request_body, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
// Both live and test webhooks are sent to the production endpoint and we want to record
// failures in both cases, but test mode errors should be reported at a lower severity.
// @see https://docs.stripe.com/connect/webhooks
$is_live_event = $event->livemode ?? true; // This is independent of self::testmode.
$log_with_severity = function( string $message ) use ( $is_live_event ) {
$is_live_event
? WC_Stripe_Logger::error( $message )
: WC_Stripe_Logger::debug( $message );
};
$log_with_severity( 'Webhook failed validation. Reason: ' . $validation_result );
$log_with_severity( 'Webhook body: ' . print_r( $request_body, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r

WC_Stripe_Webhook_State::set_last_webhook_failure_at( time() );

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 9.1.0 - xxxx-xx-xx =
* Fix - Report test webhook errors in the production environment at debug level
* Fix - Prevents duplicated credit cards to be added to the customer's account through the My Account page, the shortcode checkout and the block checkout.
* Fix - Return to the correct page when redirect-based payment method fails.
* Fix - Show default recipient for Payment Authentication Requested email.
Expand Down
Loading