There are two methods, one is IPN - which is a callback - and the other (I forget what it's called - PDT or something?) contains data posted back to your site after a purchase, which goes via the user's browser.
For maximum safety, you should implement both of them, and register the transaction on whichever one happens first (they can occur in either order).
IPN is more reliable, because Paypal will retry the IPN until it succeeds. Note that in order to handle IPN, you need to do a postback from the postback, to validate that the request is really from Paypal. You MUST implement this.
The paypal developer documentation contains all of this, and their "sandbox" site supports IPNs (Although it's occasionally a bit slow), which you can use to test your code (of course the sandbox does not handle real money).
Mark