buy function implement