'GET', 'callback' => [ $this, 'get_account' ], 'permission_callback' => [ $this, 'check_permission' ], ] ); register_rest_route( self::NAMESPACE, '/credit-balance', [ 'methods' => 'GET', 'callback' => [ $this, 'get_credit_balance' ], 'permission_callback' => [ $this, 'check_permission' ], ] ); } /** * GET /mintall/v1/account * * Ensures connection exists (auto-registers if needed) and returns account data. */ public function get_account() { $connection_data = Connection_Manager::ensure_connected(); if ( ! $connection_data ) { return new \WP_REST_Response( [ 'connected' => false, 'account' => null, ] ); } $api_key = $connection_data['api_key']; $account = Mintall_Accounts::get_me( $api_key ); if ( is_wp_error( $account ) ) { return $this->error_response( $account->get_error_message(), 500 ); } return new \WP_REST_Response( [ 'account' => $account, 'connected' => true, 'connection' => [ 'site_url' => $connection_data['connection']->site_url ?? '', 'platform_id' => $connection_data['connection']->platform_id ?? '', ], ] ); } /** * GET /mintall/v1/credit-balance * * Lightweight endpoint returning only the current credit balance. */ public function get_credit_balance() { $connection_data = Connection_Manager::ensure_connected(); if ( ! $connection_data ) { return new \WP_REST_Response( [ 'connected' => false, 'credit_balance' => null, ] ); } $api_key = $connection_data['api_key']; $account = Mintall_Accounts::get_me( $api_key ); if ( is_wp_error( $account ) ) { return $this->error_response( $account->get_error_message(), 500 ); } return new \WP_REST_Response( [ 'credit_balance' => $account['credit_balance'] ?? null, ] ); } }