d(); } catch ( SignatureVerificationException $e ) { WebhooksHealthCheck::save_status( WebhooksHealthCheck::SIGNATURE_OPTION, WebhooksHealthCheck::STATUS_ERROR ); $this->response_code = 500; $this->response = $e->getMessage(); $this->respond(); } catch ( Exception $e ) { $this->handle_exception( $e ); $this->response = $e->getMessage(); $this->response_code = $e instanceof BadMethodCallException ? 501 : 500; $this->respond(); } } /** * Get webhook stripe signature. * * @since 1.8.4 * * @throws RuntimeException When Stripe signature is not set. * * @return string */ private function get_webhook_signature() { if ( ! isset( $_SERVER['HTTP_STRIPE_SIGNATURE'] ) ) { throw new RuntimeException( 'Stripe signature is not set.' ); } return $_SERVER['HTTP_STRIPE_SIGNATURE']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash } /** * Get webhook signing secret. * * @since 1.8.4 * * @throws RuntimeException When webhook signing secret is not set. * * @return string */ private function get_webhook_signing_secret() { $secret = wpforms_setting( 'stripe-webhooks-secret-' . Helpers::get_stripe_mode() ); if ( empty( $secret ) ) { throw new RuntimeException( 'Webhook signing secret is not set.' ); } return $secret; } /** * Process Stripe event. * * @since 1.8.4 * * @param StripeEvent $event Stripe event. * * @return bool True if event has handling class, false otherwise. */ private function process_event( StripeEvent $event ) { $webhooks = self::get_event_whitelist(); // Event can't be handled. if ( ! isset( $webhooks[ $event->type ] ) || ! class_exists( $webhooks[ $event->type ] ) ) { return false; } $handler = new $webhooks[ $event->type ](); $handler->setup( $event ); return $handler->handle(); } /** * Get event whitelist. * * @since 1.8.4 * * @return array */ private static function get_event_whitelist() { return [ 'charge.refunded' => Webhooks\ChargeRefunded::class, 'charge.refund.updated' => Webhooks\ChargeRefundUpdated::class, 'invoice.payment_succeeded' => Webhooks\InvoicePaymentSucceeded::class, 'invoice.created' => Webhooks\InvoiceCreated::class, 'charge.succeeded' => Webhooks\ChargeSucceeded::class, 'customer.subscription.created' => Webhooks\CustomerSubscriptionCreated::class, 'customer.subscription.updated' => Webhooks\CustomerSubscriptionUpdated::class, 'customer.subscription.deleted' => Webhooks\CustomerSubscriptionDeleted::class, ]; } /** * Check if rest verification is requested. * * @since 1.8.4 * * @return bool */ private function is_rest_verification() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return isset( $_GET['verify'] ) && $_GET['verify'] === '1'; } /** * Respond to the request. * * @since 1.8.4 */ private function respond() { $this->log_webhook(); wp_die( esc_html( $this->response ), '', (int) $this->response_code ); } /** * Log webhook request. * * @since 1.8.4 */ private function log_webhook() { // log only if WP_DEBUG_LOG and WPFORMS_WEBHOOKS_DEBUG are set to true. if ( ! defined( 'WPFORMS_WEBHOOKS_DEBUG' ) || ! WPFORMS_WEBHOOKS_DEBUG || ! defined( 'WP_DEBUG_LOG' ) || ! WP_DEBUG_LOG ) { return; } // If it is set to explictly display logs on output, return: this would make response to Stripe malformed. if ( defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) { return; } $webhook_log = maybe_serialize( [ 'event_type' => $this->event_type, 'response_code' => $this->response_code, 'response' => $this->response, 'payload' => $this->payload, ] ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( $webhook_log ); } /** * Get webhooks events list. * * @since 1.8.4 * * @return array */ public static function get_webhooks_events_list() { return array_keys( self::get_event_whitelist() ); } }
Fatal error: Uncaught Error: Class "WPForms\Integrations\Stripe\Api\WebhookRoute" not found in /htdocs/wp-content/plugins/wpforms-lite/src/Integrations/Stripe/Stripe.php:49 Stack trace: #0 /htdocs/wp-content/plugins/wpforms-lite/src/Integrations/Loader.php(88): WPForms\Integrations\Stripe\Stripe->load() #1 /htdocs/wp-content/plugins/wpforms-lite/src/Integrations/Loader.php(73): WPForms\Integrations\Loader->load_integration(Object(WPForms\Integrations\Stripe\Stripe)) #2 /htdocs/wp-content/plugins/wpforms-lite/src/Integrations/Loader.php(22): WPForms\Integrations\Loader->__construct() #3 /htdocs/wp-includes/class-wp-hook.php(324): WPForms\Integrations\Loader::get_instance('') #4 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(Object(WPForms\Providers\Providers), Array) #5 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #6 /htdocs/wp-content/plugins/wpforms-lite/src/WPForms.php(328): do_action('wpforms_loaded') #7 /htdocs/wp-includes/class-wp-hook.php(324): WPForms\WPForms->objects('') #8 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #9 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #10 /htdocs/wp-settings.php(578): do_action('plugins_loaded') #11 /htdocs/wp-config.php(100): require_once('/htdocs/wp-sett...') #12 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #13 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #14 /htdocs/index.php(17): require('/htdocs/wp-blog...') #15 {main} thrown in /htdocs/wp-content/plugins/wpforms-lite/src/Integrations/Stripe/Stripe.php on line 49