If you know where the return URL is intended to be when they arrive back from PayPal to their purchasing page then you could load "my_link"
with php variables and use it to redirect when they arrive back:
<?php
$my_link = 'http://site-address.com/file.php?';
$my_link .= 'id=' . $id;
$my_link .= '&code=' . $code;
$my_link .= '&sum=' . $sum;
header("Location: $my_link");
exit;
?>
Looking at this page Setting PayPal return URL and making it auto return? Prashanth Pratapagiri's answer seems to suggest it is the "return" and not the notify_url which does the work, so you would need this on a hidden input for use before it is submitted:
<input type="hidden" name="return" value="<?php echo $my_link; ?>"/>
These might have a few pointers to help with setting up query strings with JavaScript: HTML form not changing URL as expected
IPN -Instant Payment Notification might help, and PayPal provide basic scripts for that which enable you to do processes which are in response to the instant notification when you get it. This has a fair bit of explanation: using paypal button - can my webpage tell if paypal transaction was successful or not?