Add query pay logic