I set up a similar affiliate program last year.
First, adding an affiliates program is probably not worth your time and effort. Very few people will ever deliver you many sales, and some who do will do it via scummy techniques.
But moving on to actually answer your question...
Affiliate tracking is typically done by having a URL parameter with the referrer id, which on page requests you convert to a cookie. On your store, upon successful sale, check if the cookie is present, and if so, record that the affiliate got you a sale.
Even if E-Junkie, PayPal, etc handle your payment processing, as long as your purchase process ends with the customer on a URL on your domain, this will work.
eg Your affiliate links to example.com?ref=123. On your server, on receiving a page request, check for the ref parameter, and turn into a long-lived cookie.
- A cookie expiry date of today+180 days is fair.
- In the case of two affiliates sending you the same customer, it is preferable to let the first person wins. This means that you should only set the affiliate cookie if it isn't already set.
- Be generous if you want people to actually send you traffic. Consider offering between 30% and 50% of the refund price.
- Don't pay out until your refund period is over plus a small buffer - this helps reduce fraud problems.
- Don't pay out until the affiliate has sent you at least two or three paying customers - this prevents people from using the affiliate program to get themselves a discount on their own purchase of your product.
If you want to see my affiliate system take a look at https://pokercopilot.com/affiliate. Feel free to sign up to see how I've done it. It won't do any damage.