Share via

Using standard PayPal buy now buttons - need an extra step to obtain a User Id

Matt Lee 40 Reputation points
2026-04-23T16:47:22.29+00:00

My asp.net site has a product page.aspx with the standard Buy now button code from Paypal.

I capture the email address of the sender from the page that has a asp.net form.

On button click, the data is saved in database and they then see a PayPal button that was previously hidden.

The user could have a different email when they checkout on Paypal account and so I need to create

a parameter that ID's the User with the data they first submitted in the form and the PayPal check out process.

Any suggestions would be helpful

thank you

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Jack Dang (WICLOUD CORPORATION) 17,340 Reputation points Microsoft External Staff Moderator
    2026-04-24T04:02:27.8866667+00:00

    Hi @Matt Lee ,

    Thanks for reaching out.

    The way to handle this is to use your own internal ID instead of trying to match on email address. After the user submits the ASP.NET form and you save their details to the database, generate or retrieve the record ID for that submission, then pass that value into the PayPal button using the custom field.

    For example:

    <input type="hidden" name="custom" value="<%= PendingOrderId %>" />
    

    When PayPal sends the transaction details back, that same custom value is included, so you can use it to look up the correct record in your database and link the payment to the original form submission even if the buyer uses a different PayPal email address.

    One important point is not to rely only on the return page in the browser to confirm payment. It is better to use PayPal’s server-side notification flow and read the custom value there before marking the record as paid. That gives you a more reliable way to reconcile the payment with the correct user data.

    Also, make sure the value you pass is just a safe reference such as an order ID or GUID, and not any sensitive customer information.

    Hope this helps! If my explanation and suggestion were helpful to you, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.


  2. Q&A Assist
    2026-04-23T16:47:40.74+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Use an internal ID that is generated and stored on the server, then pass that ID through to PayPal and back to your site.

    A simple pattern in ASP.NET Web Forms is:

    1. When the user submits the ASP.NET form (before showing the PayPal button):
      • Create a new record in the database for this pending purchase.
      • Use your own primary key (for example, OrderId or UserToken, typically an INT identity or a GUID).
      • Save all the user data (including the email they entered) against that key.
    2. Put that key into the PayPal button as a custom field
      • Standard PayPal buttons support fields such as custom or invoice that are sent back to you in IPN / return.
      • In the page that renders the PayPal button, set the hidden field value from the server:
         <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
             <input type="hidden" name="cmd" value="_xclick" />
             <input type="hidden" name="business" value="your-paypal-email@example.com" />
             <input type="hidden" name="item_name" value="Your Product" />
             <input type="hidden" name="amount" value="10.00" />
             <!-- Your internal ID -->
             <input type="hidden" name="custom" value="<%= PendingOrderId %>" />
             <input type="submit" value="Buy Now" />
         </form>
      
      Where PendingOrderId is set in code-behind when the form is processed:
         protected int PendingOrderId;
         
         protected void Page_Load(object sender, EventArgs e)
         {
             if (!IsPostBack)
             {
                 // After saving form data to DB
                 PendingOrderId = SaveFormAndGetOrderId();
             }
         }
      
    3. On PayPal return / IPN handler
      • Configure PayPal to call a server endpoint (webhook/IPN handler) on your site.
      • In that endpoint, read the custom (or invoice) field from the POST data PayPal sends.
      • Use that value to look up the record in your database and link the PayPal transaction (transaction ID, PayPal email, status) to the original form data.

    This way the user’s PayPal email can be different from the one entered on your site, but both are tied together via your own internal ID, not by email.

    The Wingtip Toys PayPal sample uses a similar idea by storing order information in the database and then associating PayPal responses with that stored data when the user returns from PayPal.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.