I don't think the issue is in this code. I think it is in the checkout code with paypal. Probably the code on the pp_confirm.php page if you are using express checkout, or on confirm.php if you are using direct payments.
Please attach that page and I'll take a look.