PayPal Hacks. 100 Industrial-Strength Tips and Tools Free Open Book

PayPal Hacks. 100 Industrial-Strength Tips and Tools

Previous Section  < Day Day Up >  Next Section

Hack 74 Provide an Order Summary with IPN

figs/moderate.gif figs/hack74.gif

Present order-specific information on the return page after the customer makes payment.

The return URL and the IPN processing script are two pages on your site that can receive posts containing details of a purchase. Used separately, these two pages can enable you to create a more robust eCommerce system by providing order-specific customization.

Using the return page, for instance, you can display the order number [Hack #52] to the customer for later use. Using the IPN system, on the other hand, you can send a customized email to the customer [Hack #71], giving her that same order number for tracking purposes. When these two features are used together, they can be even more powerful in terms of their ability to present your customer with valuable information.

This hack uses the return page to show the buyer whether the order has been processed successfully by the IPN system. By itself, this feature might not be worth much, but the functionality is called on for more advanced functions, such as delivering digital goods [Hack #72] .

When a customer reviews the payment information at PayPal and clicks the Pay button, PayPal sends a POST to your IPN page with the purchase information. The customer is directed to a PayPal page that shows them the payment confirmation message. There, the buyer sees a Continue button that, when pressed, returns the user back to the return page at your site. Order-specific information is also sent to this page.

In almost all cases, the IPN page will already have been hit and have processed the information, so you have the transaction information in your local system. With that information, you can customize the return page to give your customer order-specific information.

Exactly when your IPN page is hit by the PayPal system—and, therefore, the exact time the customer's order information is made available to your system—is not defined by PayPal. While it usually occurs quite quickly (the I in IPN stands for Instant), the possibility exists for IPN postings to be queued up at PayPal and delayed for minutes or longer. For best results, build your software to be tolerant of this possibility.


In this example, you simply display a message that notifies the customer of whether the order has been completed in your system. While this hack only displays a message, you can include other things as well. You might also want to display any error information, such as a price-checking error [Hack #73] .

This hack relies on an IPN page that inserts payment details into your database [Hack #82] which checks the database table to determine whether the order has been processed.

7.14.1 The Code

The return page receives purchase details from PayPal through a form POST (if enabled; see "Using a Return URL" in [Hack #66] for more information). Included in the purchase details is the order transaction ID, passed as txn_id. Compare this unique variable to your database to see if the order has been inserted into the table, which indicates whether it has been processed by your system.

See the "Database Coding and Platform Choices" section of the Preface for the additional information needed to put this SQL statement to work with this and the other hacks in this book.


First, you need to pass the value as presented by PayPal into a local variable using the following code:

<%

'Create local transaction id variable and populate

Dim txn_id

Txn_id = Request.Form("txn_id")

%>



'Query the database table and find the record (if it is there yet).

connStore = "DRIVER={Microsoft Access Driver (*.mdb)};

                DBQ="C:/InetPub/wwwroot/database/dbPayPal.mdb")

set rsOrder = Server.CreateObject("ADODB.Recordset")

rsOrder.ActiveConnection = connStore

rsOrder.Source = "SELECT payment_status FROM tblOrders 

                WHERE txn_id = '" & txn_id & "'"

rsOrder.Open( )

%>

<% If Not rsOrder.EOF Or Not rsOrder.BOF Then 'order exists %>

Your order has been processed successfully. The payment status for 

                this order is: <%=rsOrder("payment_status")%>

<% End If %>



<!-- Tell the customer if the order information has not yet been processed -->

<% If rsOrder.EOF Or rsOrder.BOF Then 'order does not exist %>

Your order is still being processed.

<% End If %>

As this hack illustrates, the return page and the IPN page are more powerful when used in conjunction with one another.

Ideally, you don't want to use your return page to process any of the payment information. You want to use the return page only to read the values from PayPal or read the information created by your IPN page. The return page is not completely reliable, because customers might close their browsers when they see the payment confirmation screen at PayPal, rather than follow the Continue link.


    Previous Section  < Day Day Up >  Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y]


         Main Menu
    PayPal Hacks
    Table of Contents
    Copyright
    Credits
    Preface
    Chapter 1. Account Management
    Chapter 2. Making Payments
    Chapter 3. Selling with PayPal
    Chapter 4. Payment Buttons
    Chapter 5. Storefronts and Shopping Carts
    Chapter 6. Managing Subscriptions
    Chapter 7. IPN and PDT
    Introduction: Hacks #65-86
    What IPN and PDT Are
    How IPN Works
    Advantages of PDT
    Hack 65 Receive Instant Payment Notifications
    Hack 66 Troubleshoot Instant Payment Notifications
    Hack 67 Send a Purchase Confirmation Email with IPN
    Day Day Up
    Hack 69 Use IPN with eBay Listings
    Hack 70 Track Your eBay Products with IPN
    Hack 71 Deliver Digital Goods with IPN
    Hack 72 Deliver Digital Goods with a Return Page
    Hack 73 Implement Price Checking with IPN
    Hack 74 Provide an Order Summary with IPN
    Hack 75 Upsell Your Customers
    Hack 76 Enable Multiple IPN Pages
    Hack 77 Use Mass Pay to Create an Affiliate System
    Hack 78 Manage Your Inventory with IPN
    Hack 79 Display Donation Goals on Your Web Site
    Hack 80 Display a Recent Donor List
    Hack 81 Capture Customer Information with IPN
    Hack 82 Insert Payment Details into a Database with IPN
    Hack 83 Insert Cart Details into a Database
    Hack 84 Track Google Referrals
    Hack 85 Process Payments like a Credit Card with PDT
    Hack 86 Synchronizing PDT and IPN
    Chapter 8. The PayPal Web Services API
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele