@@ -95,7 +95,8 @@ public function connect_oauth( $state, $code, $type = 'connect', $mode = 'live'
9595 // The state parameter is used to protect against CSRF.
9696 // It's a unique, randomly generated, opaque, and non-guessable string that is sent when starting the
9797 // authentication request and validated when processing the response.
98- if ( get_transient ( 'wcs_stripe_connect_state_ ' . $ mode ) !== $ state ) {
98+ $ stored_state = get_transient ( 'wcs_stripe_connect_state_ ' . $ mode );
99+ if ( $ stored_state !== $ state ) {
99100 if ( WC_Stripe_Helper::is_verbose_debug_mode_enabled () ) {
100101 WC_Stripe_Logger::error (
101102 'OAuth: Invalid state received from the WCC server ' ,
@@ -105,6 +106,7 @@ public function connect_oauth( $state, $code, $type = 'connect', $mode = 'live'
105106 'connect_type ' => $ type ,
106107 'state ' => self ::redact_string ( $ state ),
107108 'code ' => self ::redact_string ( $ code ),
109+ 'stored_state ' => false === $ stored_state ? 'false ' : self ::redact_string ( $ stored_state ),
108110 ]
109111 );
110112 }
@@ -196,16 +198,22 @@ public function maybe_handle_redirect() {
196198 }
197199
198200 if ( $ is_verbose_debug_mode_enabled ) {
199- WC_Stripe_Logger::debug (
200- 'OAuth: Account connected successfully, reloading the page to clear URL parameters ' ,
201- [
202- 'current_stripe_api_key ' => WC_Stripe_API::get_masked_secret_key (),
203- 'connect_mode ' => $ mode ,
204- 'connect_type ' => $ type ,
205- 'connect_response ' => self ::redact_sensitive_data ( $ response ),
206- 'redirect_url ' => self ::redact_sensitive_data ( $ redirect_url ),
207- ]
208- );
201+ $ log_data = [
202+ 'current_stripe_api_key ' => WC_Stripe_API::get_masked_secret_key (),
203+ 'connect_mode ' => $ mode ,
204+ 'connect_type ' => $ type ,
205+ 'state ' => self ::redact_string ( $ state ),
206+ 'code ' => self ::redact_string ( $ code ),
207+ 'nonce ' => self ::redact_string ( $ nonce ),
208+ 'connect_response ' => self ::redact_sensitive_data ( $ response ),
209+ 'redirect_url ' => self ::redact_sensitive_data ( $ redirect_url ),
210+ ];
211+
212+ if ( ! is_wp_error ( $ response ) ) {
213+ WC_Stripe_Logger::debug ( 'OAuth: Account connected successfully ' , $ log_data );
214+ } else {
215+ WC_Stripe_Logger::error ( 'OAuth: Account connection failed ' , $ log_data );
216+ }
209217 }
210218
211219 wp_safe_redirect ( esc_url_raw ( $ redirect_url ) );
0 commit comments