guard( 'manage_pointics', 'manage_options' ); if ( null !== $guard ) { return $guard; } $ready = $this->pointics_tables_ready(); if ( null !== $ready ) { return $this->steer( $ready ); } // NeuronAI passes an explicit null for a property the model omitted, so the // defaults have to live here rather than in the signature. $page = max( 1, min( self::MAX_PAGE, $page ?? 1 ) ); $per_page = max( 1, min( self::MAX_PER_PAGE, $per_page ?? 20 ) ); $query = [ 'page' => $page, 'per_page' => $per_page, ]; if ( null !== $is_active ) { $query['is_active'] = $is_active; } if ( null !== $integration && '' !== trim( $integration ) ) { $query['integration'] = sanitize_text_field( $integration ); } if ( null !== $redeem_type && '' !== trim( $redeem_type ) ) { $query['redeem_type'] = sanitize_text_field( $redeem_type ); } try { $request = new \WP_REST_Request( 'GET', '/pointics/v1/rewards' ); if ( method_exists( $request, 'set_query_params' ) ) { $request->set_query_params( $query ); } foreach ( $query as $key => $value ) { $request->set_param( $key, $value ); } $controller = pointics_container()->make( \Pointics\Api\Controllers\Rewards_Controller::class ); $data = $this->extract_response( $controller->list_rewards( $request ), __( 'Failed to list Pointics rewards.', 'aisentic' ), 'pointics-list-rewards' ); if ( $this->is_error( $data ) ) { return $data; } return $this->shape_paginated( $data, fn( array $item ): array => $this->with_admin_url( $this->pluck( $item, [ 'id', 'name', 'integration', 'redeem_method', 'redeem_type', 'cost_points', 'value', 'currency', 'is_active', 'sort_order' ] ), 'rewards' ) ); } catch ( \Throwable $e ) { Log::error( 'Pointics_List_Rewards_Tool error', [ 'error' => $e->getMessage() ] ); return $this->steer( [ 'error' => __( 'Failed to list Pointics rewards.', 'aisentic' ), 'code' => 'internal', 'status' => null, ] ); } } }