Assuming you would be the seller;
Use the IPN Postback at Paypal and script the buy page to add a hidden field in the post to Paypal include the refer's ID.
When the sale posts back you do something with the referrer ID posted back.
This has to be programmed and there are example INP post back scripts in various programming languages at Paypal.
https://developer.paypal.com/docs/classic/ipn/gs_IPN/