Rapid E-commerce Development with Dreamweaver UltraDev and PayPal

By Joel Martinez and Ray West (www.basic-ultradev.com)

This article examines how to integrate UltraDev with PayPal using a set of free server behaviors to solve three common online sales scenarios. The server behaviors, called the PayPal Extension Suite, are available from Mike Ahern at Shore Computers (http://www.shorecomp.com/ultradev/paypal/default.asp). The suite is free, but we would encourage you to make a donation, using PayPal, if you use his work.

Using the PayPal Shopping Cart even without the aid of this server behavior suite requires only knowledge of HTML. If you can cut-and-paste text, you can easily take advantage of this functionality without the aid of this extension. However, this suite integrates extremely well with UltraDev, and gives you an easy to understand user interface. The follow three examples will teach you to use the PayPal system for three common types of transactions:
  • The single item purchase which allows you to sell one item in an auction type setting.
  • The simple shopping cart which allows you to set up multiple items that can be purchased in one PayPal transaction
  • The database driven shopping cart which allows you to set up an inventory system that can be managed and delivered to your pages dynamically from a database.

Creating an E-Commerce site with PayPal

Creating an e-commerce site using PayPal is perhaps the easiest solutions to implement. The time saved in development can make this an attractive option for the project on a budget. There are certainly tradeoffs. Since all of the cart dynamics are taken care of in a popup window, other than the ability to include your logo on the cart, there is little room for customization. That being said, most sites will not require a totally customized user interface, and as such benefit greatly from using this system. The familiar interfaces produced by PayPal can actually serve to bolster consumer confidence.

This being a suite of extensions, there are a number of server behaviors, each with slightly different functionality. They do, however, share certain common elements.
  • PayPal Email - Each server behavior will require you to enter the email address used for your PayPal account. If you are going to be conducting business through your account, then you definitely want to choose the Business account.
  • Static/Dynamic fields - Almost every server behavior uses fields that allow you to choose items from the data bindings window in UltraDev, or use static values. The only thing that you have to remember is that to use a static value, it must be in double quotes. (i.e. "5.00")
  • Money - All monetary fields must be in "xx.xx" format. If you are assigning a value from the data bindings palette to one of these fields, make sure they are in this format. You can use the built in UltraDev functionality to assign a formatting scheme to this value.

Figure 1: Data bindings palette assigning monetary formatting.
  • URL Fields - Some of the server behaviors ask you for a logo URL, or a location to send the user after a transaction is processed. All of these must be absolute URLs, which means that the http://www.yourdomain.com must be included.
The Server Behaviors

The Server Behaviors below are available in the suite to allow you to interface with the PayPal functionality.
  1. The Single Purchase Behavior
    When applied to an image or some text, this server behavior makes a link straight the to PayPal checkout screen. It allows you to produce links such as "Buy me now!". This comes in handy for sites that sell only one product or service.
  2. The From Your Cart Behavior
    If you decide to use another shopping cart solution like the UltraCart II, you can still use the services provided by PayPal to accept payment for your products. The only information you need to provide (aside from your PayPal ID and several URLs) is an order number, and a total sale amount. This information is easily gathered, and passed into the simple user interface.
  3. The Add Item To Cart Behavior
    This is perhaps the server behavior that will get the most mileage. The Add Item to Cart behavior integrates very easily with a database display screen of items, allowing customers to shop around and add items to their cart. Whenever the generated link is clicked, a popup window is launched with the contents of your cart in a nice display. Users can then proceed from this screen to the checkout area where they can either log in to their PayPal account, or just supply the payment information.
  4. The View Cart Behavior
    Used in conjunction with the "Add item to cart" behavior, clicking on a link generated by the View Cart server behavior pops up a window with the contents of your cart. The only information needed is your PayPal email ID.
  5. The Donation Behavior
    The link that is produced by this server behavior will take the user to a screen where they can send you money from their PayPal account. People that sell shareware, or non-profit organization can benefit from this approach because it gives you the ability to accept money from your website without it being tied to a specific purchase.
  6. The Subscription Behavior
    Websites that offer subscription based access to their content will benefit from this unique service offered by PayPal. Users who sign up for a subscription service, will receive a recurring monthly bill from PayPal. The money goes straight into your PayPal account, and you get an email with every payment notifying you of the user's continued subscription. The link generated by this server behavior pops up a window that asks the user for their billing information.

Practical applications for the PayPal suite

There are two common scenarios that encompass most of the e-commerce scenarios on the web today. The single purchase is akin to the auction model in that a seller is offering only one item, and when it is gone it is gone. The shopping cart model involves the sale of multiple items, and possible multiple copies of those items. Following are three examples using the PayPal service to offer a single item for sale, a shopping cart using the PayPal Shopping Cart, and a shopping cart using a third party cart to interface with PayPal.

We created a demo site that can be found at http://www.codecube.net/teksales/. The examples outlined in this article can be found at the demo site.

Figure 2: teksales demo site

"I'll have one, please" - The Single Item Sale

The single purchase server behavior is used when you have one item to sell. eBay users have long embraced this functionality to collect payment for their auctions. If your site is selling more than one item, then there are other behaviors that will serve you better. But for the one-off sale of a used or collectible item, the single purchase server behavior provides a quick, simple to use option.

Picture this; you've got the hottest motorcycle around, the Ducati Monster S4Fogarty. One day you're riding around when a car suddenly cuts you off changing lanes. All of a sudden your life is flashing before your eyes, and you can't bear to ride the bike another foot without breaking into a cold sweat. So you decide to sell it on your website. You make quick design in Ultradev, and post it on your site.

Figure 3: Ducati sale site...pre SB

You figure people will be lining up at the mailbox to mail you the money for this street rocket, but alas, they don't come. There could be several reasons. Perhaps the price is more than many people can write a check for.

Using the Single purchase server behavior

Using the single purchase server behavior is quite simple. Once your page is designed, you need only choose an object on the page to act as the purchase button. This might be either a "Buy Me" image, or some text that conveys the same message. Highlight the object and apply the server behavior as you would any other. The single purchase server behavior can be found in the server behaviors palette under PayPal > PayPal Single Purchase.

Figure 4: pp_SinglePurchase

Fill out the fields in the server behavior's interface and you are all done. When a user clicks on the link generated by the behavior, a window containing payment collection information pops up, and the user is taken through the checkout process. You will receive confirmation of the completed sale from PayPal and you can then go about boxing up the motorcycle for deposit in your local mail receptacle.

"I'll take two of each" - The Simple Shopping Cart

The single purchase sale makes up a great many of today's internet-based transactions, especially with the popularity of online auctions. But those who intend to make their web site an ongoing business face additional concerns. They often carry a variety of products and hope that their customer will make multiple and repeat purchases from their inventory.

We return to you, our budding motorcycle salesman. The sale of your Ducati made you realize the demand that exists for motorcycle related merchandise, so you have decided to build an online business that provides some. With the new PayPal online payment solution, your business is booming. You are making a great profit reselling motorcycles through your website, but you want more you decide to start selling some products to complement your motorcycle sales such as helmets and goggles. This is a simple enough concept, but you cannot continue using the same solution. On your weekly trip to Wal-Mart, you realize what you must do when you pick up a can of degreaser, and put it in your shopping cart along with the milk and eggs. You need a shopping cart, too.

In simple terms, an online shopping cart allows your visitor to purchase multiple items in one transaction. As the customer navigates through the site viewing merchandise and choosing which items to purchase, the shopping cart 'remembers', either through the use of session variables, cookies, and a database, which items were picked. When the customer decides to checkout, they can enter payment information once and the order will be placed for all of their items.

Using the PayPal Shopping Cart

Using the Shopping Cart Server behavior is very similar to the Single Purchase behavior. But because this behavior is to be used with a shopping cart, there are a couple of notable differences. First, the is the option to allow your customer to select the quantity of a particular item, like two pairs of gloves or three leather pants patch kits. Also, the action that is performed when the purchase button is clicked simply adds the item to a shopping cart and allows continued shopping rather than trying to collect payment information immediately.

To apply the Server Behavior to you item, simply highlight an object or text on your page and choose the Add to Cart Server Behavior from PayPal > PayPal Add Item to Cart in the Server Behaviors Palette. Repeat for each item in your site.

The link created will pop up a new window to the PayPal shopping cart system, and will display every item that you have added. If you click on the same item twice, the quantity amount will increase by one. This is the preferred method in this situation because shoppers want to do as little as possible to get their products, so if you save them even a couple of clicks, they are happier and happier customers buy more stuff.

Using PayPal with a Database Driven Shopping Cart

The previous examples are good learning exercises, and there may even be times when you are in a similar situation and just need very basic PayPal functionality. But the power of this extension suite really shows when it is used in conjunction with a database driven inventory solution. When you use a database to manage your products, it can take a little more up front development time, but the benefits become evident later on down the road with ease of maintenance and management. If constructed correctly, your site essentially goes on autopilot.

Table Structure

The most time consuming portion of the construction of this type of site, is the database itself. Actually hooking into the PayPal shopping system is almost trivial. For the purpose of this discussion, we will use a classic parent/child - master/detail data structure. This is the database layout that is used in 99% of databases across the net. If you need some help with the database portion of this project, there are many resources around the web that can assist you.

For every row in the parent table, there can be zero to many rows in the child table. In the context of an e-commerce site, this means that we are going to have a category table as the master, and the product table as the child. An example of some data that might be held within:

TV category
- Sony 20"
- RCA 19"
- Magnavox 32"

VCR category
- Panasonic Two Head
- Samsung Four Head

Begin by defining the Category table with the following fields:
  • catID - autonumber
  • catName - text
As you can see, a master table usually does not need a lot of information, as it is just an organizer for the numerous rows in the child table. Some other information that could potentially be held in this table include:
  • an Extended description
  • a category picture
  • an Active Field that indicates whether this category is currently active
This table can be used on a page that lists all of the categories of items that are available at your site. The customer can then select a category to see the details of the products that are available in each category.

The next table that we need, is the product table. This will hold information on each individual product, so it needs to include a field for each corresponding item in the Add to Cart Server Behavior.
  • itemID - autonumber
  • catID - number
  • itemName - text
  • amount - currency
  • shipping - currency
  • handling - currency
If you won't be using some of these fields (not charging for shipping and handling for instance) you can just populate them with zeros.

As with the category table, we are using the bare minimum fields for the sake of brevity. Other possible fields include:
  • Date added
  • Active
  • Page Views

Figure 6: tekDB_relationship
A graphical representation of the relationship between the two tables

Once you have the database structure set up, populate the tables with some test data. This can be replaced later with production data. First, create several categories.

Figure 7: tekDB_catTableContents

Keep in mind that each category is merely a logical container for the child products. A relationship is established between the category table and a particular product by placing the "catID" of the parent category in the numeric "catID" field of the products table. A more complex table structure could be created to handle products are might fall under more than one category, but this will suffice for now.

Figure 8: tekDB_ProductTableContents

Displaying the data

Once the database has some data you can work with, the next step is to put the data on a page. Only two pages are needed for this demonstration, a master page displaying all categories for the user to choose from, and a detail page showing all items for the chosen category.

First, create an HTML table for the user interface. A table with 2 x 2 dimensions will work fine. The first row will be a simple header, describing the contents of the column below it, and the second row will be where the recordset output is held. Create a recordset that chooses the category name and ID from the table.

Drag the category name from the data source palette to the first column second row. The second column will hold a "view" link.

To create the view link, begin by highlighting the text and using the property inspector to navigate to the page on which the products will be displayed. Click the folder icon and you will be presented with a list of the existing pages within your site. Select the products page and then click the Parameters button near the bottom of the dialogue box. It the Parameters window, you can create a URL parameter called catID (which is used in the products recordset to filter) and assign a value from the database by selecting the catID field using the lightning bolt icon. Now when the view button next to that category is click, the corresponding ID will be passed to the products recordset in the URL string and only the products in that category will be displayed on the detail page. Once that is completed, you can add the repeat region server behavior to the second row.

Now that we have the category page working, the next step is to create the detail page. We know that anyone arriving at this page will be from the category page and as such will have the catID in the query string. So we begin by creating a recordset that gets every field in the table, we filter the catID by the value from the query string using request("catID").

Figure 9: tekDB_categoryRS

The user interface for this table can have exactly the same layout, except for an extra column for the price. Drag the item name to the first column, the price to the second, and type "Add to cart" in the third. Highlight the "Add to Cart" text, and choose the Add to Cart Server Behavior from the Server Behavior's Palette. Most of the fields on the user interface have a little lightning bolt next to the textbox. These allow you to populate the fields with fields from your database via the recordset that you have created in the Data Sources Window. Choose a field from the database for each corresponding item in the server behavior. Once this is done, you can add a repeat region to the second row. When the products are populated onto the page from the database at run time, each Add to Cart instance will have the appropriate information attached. Any item that is clicked for purchase will update the shopping cart with the information that you have entered. Maintenance can now be performed on item within the database without having to edit your HTML pages.

Figure 10: tekDB_Addtocart

That is about all there is to it. Customers can now browse your catalog of items, choose the ones they wish to buy, and check out. Rapid application development is one of the main things that make the PayPal suite a great e-commerce contender. Other shopping cart systems take a great deal of development time without really addressing the payment collection issue. This demo was created in about an hour using the power of Dreamweaver UltraDev and the PayPal extension suite.

This article is an excerpt from the new book UltraDev E-commerce Concepts: Next Steps by Ray West, Tom Muck and Joel Martinez. For more information about UltraDev and E-commerce, please visit Basic UltraDev at www.basic-ultradev.com. There you will find information about our books, tutorials and extensions that can greatly increase your web development capabilities.

DISCLAIMER: The following content is provided by each article's individual author and not by PayPal, Inc. or any of its affiliates or subsidiaries. The articles may contain errors, and PayPal does not endorse or provide support for their content. PayPal advises that you contact the authors of the articles for questions, information about technical support, warranties and/or licenses, if any are necessary. If you choose rely on the content in any of these articles, you do so at your own risk. PayPal will take no responsibility for any errors, harm or other damage that may occur as a result of your reliance on this content, including any incidental, special, indirect or consequential damages. PayPal EXPRESSLY DISCLAIMS ALL WARRANTIES regarding this content and the use of this content.