'Not able to persist the Paypal payment Id to complete the payment flow

I'm trying to follow the paypal flow for Accepting a Paypal Payment where the user chooses to pay with their paypal account and I'm coding in Java. The flow redirects the user to the paypal website to approve the payment and then returns control to the specified return url where you are supposed to complete the flow by executing the approved payment. This makes sense.

Here's where I'm running into trouble. To execute an approved payment, I need to be able to set the payment id which was provided prior to approval. However, there seems to be no way to persist the payment id because the user is redirected to the paypal site to approve the payment which causes the session to be destroyed (so it can't be stored in session), the cookies are lost (so it can't be retrieved as a cookie) and there is no uniquely identifying information for the user unless you force the user to login prior to making a purchase (so the payment id can't be stored in a database and tied to the user). I thought about using the ip address of the user but the request may be emanating from a network with multiple users. There seems to be no way of completing the flow.

Is anyone else having this problem? Can someone help with this?



Solution 1:[1]

You can pass your payment ID to PayPal using the item_number or custom variables. That information would be sent to your return page and in an IPN post. You can use that to help track buyers.

When you get that IPN post back you can write the payment ID you passed throughcustom with the transaction ID you get from PayPal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gerzie