storage = $storage; $this->api_client = $api_client; } /** * Run the synchronous submission flow. * * @since 1.2.0 * @since 1.8.0 Report explicit quota or authentication failures and authenticated recovery. * * @param array $normalized_data Prepared submission payload. * @param array $meta Submission metadata (must include tracking_mode). * @param string $provider_slug Integration slug. * * @return array{ * success:bool, * verdict?:string, * submission_id?:string, * tracking_mode?:bool, * error?:string * } */ public function process( array $normalized_data, array $meta, string $provider_slug ): array { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh try { $submission_id = $this->storage->create_pending( $normalized_data, $meta ); } catch ( Exception $e ) { Logger::log( 'Sync mode: failed to persist submission', [ 'provider' => $provider_slug, 'error' => $e->getMessage(), ] ); return [ 'success' => false, 'error' => 'storage_error', ]; } $client = $this->api_client ?? new ApiClient(); $api_result = $this->call_check_endpoint( $client, $normalized_data ); /** * Report an authenticated check outcome using only local submission identity. * * @since 1.8.0 * * @param array $result Parsed success or explicit machine-readable failure. * @param string $submission_id Local stored submission identifier. * @param string $scope Local credential fingerprint. * @param string $provider Integration slug. * @param mixed $form_id Local form identity. */ do_action( 'activelayer_protection_check_result', $api_result, $submission_id, hash( 'sha256', SettingsHelper::get_api_key() ), $provider_slug, $meta['form_id'] ?? 0 ); if ( empty( $api_result['success'] ) ) { $this->storage->update_status( $submission_id, 'failed', [ 'verdict' => 'failed', 'api_response' => [ 'error' => $api_result['error'] ?? 'unknown' ], ] ); Logger::log( 'Sync mode: API error, allowing submission', [ 'provider' => $provider_slug, 'error' => $api_result['error'] ?? 'unknown', ] ); return [ 'success' => false, 'error' => 'api_error', 'submission_id' => $submission_id, 'tracking_mode' => $meta['tracking_mode'], ]; } $verdict = $api_result['verdict'] ?? 'clean'; $this->storage->update_status( $submission_id, $verdict, [ 'api_response' => $api_result['raw_response'] ?? $api_result, 'processed_at' => current_time( 'mysql' ), 'verdict' => $verdict, ] ); Logger::log( 'Sync mode verdict', [ 'provider' => $provider_slug, 'submission_id' => $submission_id, 'form_id' => $meta['form_id'] ?? null, 'verdict' => $verdict, 'tracking_mode' => $meta['tracking_mode'], ] ); SubscriptionStats::get_instance()->schedule_refresh(); return [ 'success' => true, 'verdict' => $verdict, 'submission_id' => $submission_id, 'tracking_mode' => $meta['tracking_mode'], ]; } /** * Call the API endpoint that matches the submission's data type. * * Product reviews and comments use the comment-specific endpoint (richer * comment-model priors), matching the async worker's routing; all other * submission types use the default form endpoint. * * @since 1.5.0 * * @param ApiClient $client API client. * @param array $normalized_data Prepared submission payload. * * @return array API response. */ private function call_check_endpoint( ApiClient $client, array $normalized_data ): array { if ( in_array( $normalized_data['data_type'] ?? '', [ 'review', 'comment' ], true ) ) { return $client->check_comment( $normalized_data ); } return $client->check_submission( $normalized_data ); } }