store_integration_service = $store_integration_service; $this->namespace = $rest_namespace; $this->rest_base = $this->store_integration_service->get_rest_base(); $this->store_context = $store_context; } /** * Register the API endpoints. * * @return void */ public function register_routes() { $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ ); $args = array( self::PARAM_STORE_ID => $this->get_arg_string(), self::PARAM_SIGNATURE => $this->get_arg_string(), ); $this->register_post( $this->store_integration_service->get_endpoint(), 'handle_post', $args, 'check_permissions' ); } /** * Check the request data to see if it has permission to proceed. */ public function check_permissions(): bool { // The signature is checked in the Integration Core, no need to check it here. return true; } /** * Handle POST request. * * @throws \Exception * @param WP_REST_Request $request The request. * * @return WP_REST_Response|WP_Error */ public function handle_post( WP_REST_Request $request ) { $signature = $request->get_param( 'signature' ); $payload = $request->get_json_params(); $response = ConfigurationWebhookAPI::configurationHandler( $this->store_context->getStoreId() ) ->handleRequest( $signature, $payload ); return $this->build_response( $response ); } }