Paying referral fees

Is it legal to pay Referral Fees only if you buy the house that was referred to you?