tags:

views:

82

answers:

2

I'm setting up a payment gateway for my software product which users can buy off the web and use. I'm using paypal website payments standard to get started.

There's a basic issue troubling me. The workflow for my user is: Login to my product site (free license for a trial period) -> Pay to extend license

Now suppose a user - [email protected] registers on my site and logs in. I then show him the buy now button (paypal's). He clicks on it, gets redirected to paypal, pays, gets redirected back to my site. In the background, I set up paypal's IPN feature and get notified of this transaction and its details. Now - how do I link this purchase with my user? How do I know that [email protected] made the payment.

Note: I'm not using autoreturn + PDT method because of its basic flaw - if user closes browser after payment but before returning to the autoreturn page, my post payment logic never runs. Using IPN guarantees running of post payment logic but how do I link the payment with the username on my site that initiated and completed the payment?

+2  A: 

For your user payment you create a unique ID that you send for the payment, and you get it back on IPN.

The code to use for place it on PayPal:"invoice"

Here are the codes: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables

Look at table 4.

invoice -> Passthrough variable you can use to identify your invoice number for this purchase.

Here is a code for IPN https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside

on the if (strResponse == "VERIFIED"){... you can get the invoice... just by reading the Request.Form["invoice"]

Ps You can use both PDT and IPN and you can merge the results from both.

Aristos
"send for the payment, and you get it back on IPN"...how exactly? could you please link me to an example?
SaM
@SaM I have update my answer, on the data you send you place a unique ID that you connect with your user on the "invoice" field that you send, and then you get it back on the data you get from IPN (or PDT).
Aristos
+1  A: 

You need to set up ASP.NET Profiles for registering subscribers. This allows you to store extra details for each user in the database after they have been verified via IPN. Before sending the details to PayPal you could create a GUID to relate the order to the registered user.

If you are using the ASP.NET Web site project template, you have Profiles out of the box. If you are using an ASP.NET Web Application project template, you can use the Web Profile Builder to set up Profiles:

http://weblogs.asp.net/joewrobel/archive/2008/02/03/web-profile-builder-for-web-application-projects.aspx

Here's another cool way to do it:

http://leedumond.com/blog/asp-net-profiles-in-web-application-projects/

To link the payment with the username on your site, the lifecycle would be as follows:

1) Use PayPal Subscriptions to handle the initial free period :-)

2) User subscribes on your site and is directed to the PayPal site

3) Your IPN class handshakes with PayPal and grabs the values returned by PayPal

4) Your IPN class updates your application database and generates an email to the subscriber with a return URL to register on your site

5) Your IPN class generates an email (backup) to the merchant with the subscription data

6) The subscriber creates a user account on your site and you set up any extra member info you want to store in their profile

protected void Createuserwizard1_CreatingUser(object sender, EventArgs e)
{
    WebProfile p = WebProfile.GetProfile(CreateUserWizard1.UserName, true);
    p.Initialize(CreateUserWizard1.UserName, true);

    p.subscriberID = ViewState["SubscriberID"].ToString();
    p.subscriberExpireDate = ViewState["ExpireDate"].ToString();

    p.Save();
} 

Some Gotchas:

Do not use a return URL from PayPal

Do not mix IPN and PDT. IPN is all you need

Do not forget the Save() method when creating the profile :-S

IrishChieftain