Hack 62 Offer Tiered Subscriptions

 < Day Day Up > 

figs/moderate.gif figs/hack62.gif

Enhance simple subscription management to accommodate different levels of users .

Offering something of value for a small amount of money, and then selling your customer an upgrade to something of even greater value for a larger amount of money, is a great marketing plan. PayPal does this itself in a way; you can get some nice features for a low price (free) with a Personal account, and when you want more features you can upgrade to a Premier or Business account.

This hack shows you how to add tiers (or service levels ) to your subscribers' accounts. You can create Subscribe buttons for each of your subscription levels, add a field to your database to indicate the subscriber's tier, check the tier of subscribers when users access pages, and give your customers an easy upgrade option.

6.3.1 Creating a Premium Subscription Button

Who knew the opportunities in marketing to lower primates? Thanks to a new partnership, you now own exclusive North American distribution rights to the customer data of Rhesus Research International, a leading monkey marketing firm in Europe and Asia (this example was introduced in [Hack #61] ). You want to keep offering access to your North American data at the usual low price, but you want to add an option for buyers of your data who want to market to the rest of the world as well. Solve this problem by adding another subscription option at a higher price.

The following code includes the Subscribe button from [Hack #61] along with a new addition. Differences between the buttons are highlighted in bold:

 <html> <head><title>Monkey Market Database</title></head> <body> North American data only: <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but20.gif"                 border="0" name="submit" alt="Make payments with PayPal - it's fast,                  free and secure!"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="burchell@inebraska.com"> <input type="hidden" name="item_name" value="  Monkey Market  "> <input type="hidden" name="item_number" value="  mm-1  "> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="a3" value="  30.00  "> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> </form> <br> International option; includes Asia and Europe <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but20.gif"                 border="0" name="submit" alt="Make payments with PayPal - it's fast,                  free and secure!"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="burchell@inebraska.com"> <input type="hidden" name="item_name" value="  Monkey Market with                 International option  "> <input type="hidden" name="item_number" value="  mm-2  "> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="a3" value="  60.00  "> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> </form> </body> </html> 

When subscriptions roll in, you (and your IPN script [Hack #65] ) will be able to tell if they are standard or International by looking at the item_number .

6.3.2 Adding a Tier Field to Your Database

Modify your database (as shown in Table 6-2) to include a column called tier . This, along with the previously discussed [Hack #61] email and password , allows your system to keep track of the tier level for which your subscribers have paid.

Table 6-2. Adding a tier field to your database to keep track of subscriber levels

ID

email

password

tier

 4005 

 shannon@paypalhacks.com 

 sR3Du4#m77ca 

 

 4006 

 dave@paypalhacks.com 

 go3@c23-dad43 

 1 

 4007 

 david@paypalhacks.com 

 fae0v32c&ewf2 

 2 


6.3.3 Inserting Tier Information with Each New Subscription

Recall the approach to recording subscriptions [Hack #61] and modify the code to insert a value in the tier field based on the item_number reported :

 <!-- Standard IPN processing here --> <% if Request.Form("txn_type") == "subscr_signup" then  ' Add this subscriber to the database  ' Is it an mm-1 or an mm-2 subscriber?  If Request.Form("item_number") == "mm-1" then  ' Use SQL like this:   set cInsSubscr = Server.CreateObject("ADODB.Command")   cInsSubscr.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)};                 DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb")   cInsSubscr.CommandText = "INSERT INTO subscriber (email, password, tier)                 VALUES ( '" & Request.Form("payer_email") & "', 'drowssap', 1)"   cInsSubscr.CommandType = 1   cInsSubscr.CommandTimeout = 0   cInsSubscr.Prepared = true   cInsSubscr.Execute( )  elsif Request.Form("item_number") == "mm-2" then   set cInsSubscr = Server.CreateObject("ADODB.Command")   cInsSubscr.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)};                 DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb")   cInsSubscr.CommandText = "INSERT INTO subscriber (email, password, tier)                 VALUES ( '" & Request.Form("payer_email") & "', 'drowssap', 2)"   cInsSubscr.CommandType = 1   cInsSubscr.CommandTimeout = 0   cInsSubscr.Prepared = true   cInsSubscr.Execute( )  end  ' Email the password to the new subscriber elsif   Request.form("txn_type") == "subscr_cancel" then  ' Remove a subscriber from the database  ' Use SQL like this:   set cInsPayment = Server.CreateObject("ADODB.Command")   cInsPayment.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)};                 DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb")   cInsPayment.CommandText = "DELETE * FROM subscriber WHERE email =                  '" & Request.Form("payer_email") & "'"   cInsPayment.CommandType = 1   cInsPayment.CommandTimeout = 0   cInsPayment.Prepared = true   cInsPayment.Execute( ) end %> 

6.3.4 Restricting Access Based on Tier

You will want to check for the magic cookie [Hack #61] before giving access to pages. You will also want to set a cookie with its own secret word for the tier. This page contains International content:

 <% 'content_intl.asp 'Check for the magic cookie. 'If not found, redirect if Response.Cookies("MagicMonkey") != "swordfish"   or Response.Cookies("MagicMonkeyTier") != "lowtide" then  Response.Print("Please log in before accessing this page.")  Response.Redirect("login.asp") end %> <!-- Put your content here --> 

Don't forget to set the tier magic cookie word when subscribers log in:

 <% 'Sign in page: sign_in.asp 'Connect to database and create recordset connStore = "DRIVER={Microsoft Access Driver (*.mdb)};                 DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb") set rsTier = Server.CreateObject("ADODB.Recordset") rsTier.ActiveConnection = connStore rsTier.Source = "SELECT tier FROM subscribers WHERE email =                  '" & Request.Form("email") & "' AND password =                  '" & Request.Form("password") & "'" rsTier.Open( ) 'Assign the result to tier Dim tier Tier = rsTier("tier") 'IF the query turns up a match, execute this code: 'Set new cookie session in MagicMonkey '"swordfish" happens to be today's magic cookie word Response.Cookies("MagicMonkey") = "swordfish" 'Set cookie expiration Response.Cookies("MagicMonkey").Expires = Now( ) + 1 'one day If tier > 1 then  'Set International magic cookie  Response.Cookies("MagicMonkeyTier") = "lowtide"  'Set cookie expiration  Response.Cookies("MagicMonkeyTier").Expires = Now( ) + 1 'one day end Response.Print("Thank you for logging in. <a href="content.asp">Click                  here</a> to start selling stuff to an International bunch of monkey                 lovers.") 'ELSE do this: Response.Redirect("login.asp") %> 

6.3.5 Encouraging Subscribers to Upgrade

You can allow your current subscribers to upgrade to a better subscription by giving them a Modify Subscription button. Take the HTML code for your top-tier subscription and add a modify line. For example, the following code lets your original subscribers get on board with the new International offering:

 Upgrade now to the new International option; includes Asia and Europe <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but20.gif"                 border="0" name="submit" alt="Make payments with PayPal - it's fast,                 free and secure!"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="burchell@inebraska.com"> <input type="hidden" name="item_name" value="Monkey Market with International option"> <input type="hidden" name="item_number" value="mm-2"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="a3" value="60.00"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> <  input type="hidden" name="modify" value="2"  > </form> 

This can be a better solution than asking your customers to cancel one subscription and add another. Your records will also be simpler as a result, because PayPal will continue to use the same subscription ID in your records.

In your IPN script, add checking for a txn_type of subscr_modify . If you see that value, you need to change your database to reflect the new service tier. For example, your SQL might look like this:

 "UPDATE subscriber SET tier =                          2 WHERE email = '" & Resquest.Form("email") & "'" 

 < Day Day Up > 


PayPal Hacks
PayPal Hacks
ISBN: 0596007515
EAN: 2147483647
Year: 2004
Pages: 169

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net