Customers referal

Customers referal

I run an ecommerce platform which customers purchase an annual membership to access hundreds of deals. 

When my customers purchase the memebrship, i want to refund their payments if they refer our product to 3 of theirfriends. 

How do I setup user specific URL so I know which customers have referred them? This is currently being done manually and I want to automate through CRM if possible?