| < Day Day Up > |
Chapter 6. Managing Subscriptions
Introduction: Hacks #61-64 Hack 61. Sell Subscriptions to Your Online Content Hack 62. Offer Tiered Subscriptions Hack 63. Time Your Subscriptions to End on Specific Dates Hack 64. Manage Subscription Passwords the Easy Way |
| < Day Day Up > |
| < Day Day Up > |
Introduction: Hacks #61-64
Being paid once is a fine thing, but being paid repeatedly is fabulous. With a PayPal subscription button, you can offer your customers the chance to pay you again and again without any further human intervention. Subscription
As mentioned in the introduction to Chapter 4, PayPal provides a tool to create subscription buttons for your site. Like ordinary Buy Now buttons, these are nothing more than HTML forms that can be placed on your pages. A customer clicks a Subscribe Now button to go to the PayPal site to confirm the new subscription, and the recurring payments begin. For complete information about subscriptions and subscription buttons, see PayPal's Subscriptions and Recurring Payments Manual, available from within your PayPal account under the Merchant Tools tab. For now, keep a few facts in mind as you read this chapter:
|
| < Day Day Up > |
| < Day Day Up > |
Hack 61 Sell Subscriptions to Your Online Content
Combine a database, PayPal subscriptions, and the IPN system to manage subscriber accounts . If your web site offers something special that people are willing to pay for, such as access to a technical information database or specialized business-to-business commerce site, you might want to offer subscriptions. PayPal makes it easy. Using IPN, your web server, and your online database, you can easily create an entirely automated system.
For the purposes of this example, let's say you offer access to a Rhesus monkey marketing database for the low, low price of $30 per month. This opt-in database contains the monkey
You'll need four things to implement your subscription business model:
6.2.1 Creating a Subscribe Button
The Subscribe button for your site can come straight from PayPal's button generator on the Merchant Tools page (log into PayPal and click the Merchant Tools tab). This example (created without encryption) should look familiar if you have created any unencrypted Buy Now or Donate Now
<html>
<head><title>Monkey Market Database</title></head>
<body>
<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>
</body>
</html>
6.2.2 Setting Up Your Database
Your access control database can be simple. A single table, shown in Table 6-1, containing the email address and the password of your subscriber is all you need. For this example, the table
subscribers
contains two
Table 6-1. A database to keep track of your subscribers
6.2.3 Processing Subscriber NotificationsYou need to handle two kinds of notifications from PayPal: the addition of new subscribers to your database when they sign up and removal of subscribers whose subscriptions lapse or are cancelled. Here's a snippet of ASP that does this (see the "Database Coding and Platform Choices" section of the Preface for database considerations):
<!-- Standard IPN processing here -->
<%
if Request.Form("txn_type") == "subscr_signup" then
' Add this subscriber to the database
' 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) VALUES
( '" & Request.Form("payer_email") & "', 'drowssap')"
cInsSubscr.CommandType = 1
cInsSubscr.CommandTimeout = 0
cInsSubscr.Prepared = true
cInsSubscr.Execute( )
' 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 cDelSubscr = Server.CreateObject("ADODB.Command")
cDelSubscr.ActiveConnection = "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb")
cDelSubscr.CommandText = "DELETE * FROM subscriber WHERE email =
'" & Request.Form("payer_email") & "'"
cDelSubscr.CommandType = 1
cDelSubscr.CommandTimeout = 0
cDelSubscr.Prepared = true
cDelSubscr.Execute( )
end
%>
{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}
Don't forget to
6.2.4 Controlling Access to Your Valued Content
Now you have a list of valid subscribers that is automatically updated by PayPal and your IPN script. Next, you'll need to make use of this information by ensuring that
<%
'content.asp
'Check for the magic cookie.
'If not found, redirect
if Response.Cookies("MagicMonkey) != "swordfish" then
Response.Print("Please log in before accessing this page.")
Response.Redirect("login.asp")
end
%>
<!-- Put your content here -->
The Sign In page simply asks for the user's email address and password. If this information shows the visitor is a valid subscriber, a cookie is set on the user's browser. The cookie contains the magic word that allows your subscribers access. Without this cookie, set to the proper magic word, no one can access subscriber-only content.
<%
'Sign in page: sign_in.asp
'Database connection code goes here
'Connect to database and create recordset
connStore = "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb")
set rsCookies = Server.CreateObject("ADODB.Recordset")
rsCookies.ActiveConnection = connStore
rsCookies.Source = "SELECT * from subscribers WHERE email =
'" & Request.Form("email") & "' AND password =
'" & Request.Form("password") & "'"
rsCookies.Open( )
'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
Response.Print("Thank you for logging in. <a href="content.asp">Click
here</a> to start selling stuff to a bunch of monkey lovers.")
'ELSE do this:
Response.Redirect("login.asp")
%>
Your page, login.asp , should contain an HTML form that asks for each customer's email address and password. Its data is posted to sign_in.asp . 6.2.5 Hacking the HackThis example is purposefully simplistic. If the cookie is always the same, all a nonsubscriber needs to do to gain access is manually set the browser's cookies to include your magic word. In practice, you will want to change your magic cookie daily. Users will need to visit the Sign In screen each day and provide their email address and password to get that day's magic cookie. Better yet, use a one-way encryption algorithm to create a unique cookie each day for each subscriber. |
| < Day Day Up > |