What PayPal could help with in this case, is to pass your "custom code" (associated with the product/affiliate sys) and return it (in the async call-back message called IPN) when the payment is completed
Use JS or form variables to pass an "affiliate system ID" along with the product code, when user clicks to purchase from an affliate system
The system obtains the "affiliate sys ID" and set it into the payment button (form tag, use the custom
field)
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="get">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="usm@email.com">
<input type="hidden" name="item_name" value="Test Product">
<input type="hidden" name="amount" value="1.0">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="affiliate sys ID obtained from query string or JS">
<input type="hidden" name="return" value="http://returnAddress">
<input type="hidden" name="notify_url" value="http://IPNListener">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
User clicks the payment button and is redirected to PayPal checkout page, authorize and complete the payment.
Async IPN messages will be sent to the system, containing custom=affiliate sys ID
so that you know which affiliate sys should the trasanction be registered on.
Additionally, if you need to register a purchase even if the user backs out the payment, put some JS on the payment button form so that every user click is recorded (with the affiliate sys ID) in to the database, this part has nothing to do with PayPal though
Payment button code is simple & straight forward but if you'd integrate with APIs e.g. Express Checkout, the approach works as well
Express Checkout API reference