Skip to content

Commit

Permalink
Clear webhook state after reconfiguring webhooks (#3352)
Browse files Browse the repository at this point in the history
* Clear the stored webhook state when the merchant reconfigures webhooks

* Update mode "both" case

* Add changelog entries

---------

Co-authored-by: Diego Curbelo <[email protected]>
  • Loading branch information
james-allan and diegocurbelo authored Aug 15, 2024
1 parent 4b71491 commit c8d1fd5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

= 8.7.0 - xxxx-xx-xx =
* Fix - Fix possible fatal errors when Stripe settings format is invalid during account connection.
* Fix - Clear webhook state after reconfiguring webhooks to remove outdated error and success statuses.
* Add - Log incoming webhook events and their request body.
* Add - Show UPE payment methods in saved order on block checkout page.
* Tweak - Delete the notice about the missing customization options on the updated checkout experience.
Expand Down
3 changes: 3 additions & 0 deletions includes/class-wc-stripe-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ public function configure_webhooks( $mode = 'live', $secret_key = '' ) {

update_option( WC_Stripe::STRIPE_GATEWAY_SETTINGS_OPTION_NAME, $settings );

// After reconfiguring webhooks, clear the webhook state.
WC_Stripe_Webhook_State::clear_state();

return $response;
}

Expand Down
21 changes: 21 additions & 0 deletions includes/class-wc-stripe-webhook-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ public static function get_testmode() {
return ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false;
}

/**
* Clears the webhook state.
*
* @param string $mode Optional. The mode to clear the webhook state for. Can be 'all', 'live', or 'test'. Default is 'all'.
*/
public static function clear_state( $mode = 'all' ) {
if ( 'all' === $mode || 'live' === $mode ) {
delete_option( self::OPTION_LIVE_MONITORING_BEGAN_AT );
delete_option( self::OPTION_LIVE_LAST_SUCCESS_AT );
delete_option( self::OPTION_LIVE_LAST_FAILURE_AT );
delete_option( self::OPTION_LIVE_LAST_ERROR );
}

if ( 'all' === $mode || 'test' === $mode ) {
delete_option( self::OPTION_TEST_MONITORING_BEGAN_AT );
delete_option( self::OPTION_TEST_LAST_SUCCESS_AT );
delete_option( self::OPTION_TEST_LAST_FAILURE_AT );
delete_option( self::OPTION_TEST_LAST_ERROR );
}
}

/**
* Gets (and sets, if unset) the timestamp the plugin first
* started tracking webhook failure and successes.
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ If you get stuck, you can ask for help in the Plugin Forum.

= 8.7.0 - xxxx-xx-xx =
* Fix - Fix possible fatal errors when Stripe settings format is invalid during account connection.
* Fix - Clear webhook state after reconfiguring webhooks to remove outdated error and success statuses.
* Add - Log incoming webhook events and their request body.
* Add - Show UPE payment methods in saved order on block checkout page.
* Tweak - Delete the notice about the missing customization options on the updated checkout experience.
Expand Down

0 comments on commit c8d1fd5

Please sign in to comment.