Case Study - How to Integrate PayPal's Shopping Cart

The Goal

A customer contacted us and explained that she maintains a small inventory of sheet-music (approximatley one hundred items) and:

The Process

So, how does 20/20 DataShed fit into all of this? Well, because PayPal's system takes care of the really complicated stuff we determined that 20/20 DataShed could simply create the appropriate buttons! By editing the "item_template(Default).html" page we can use the information from the database to populate PayPal's <form> tag.

Below is a basic example of PayPal's <form> tag. This produces a button on a web page. Note that the blue text are variables that 20/20 DataShed should replace with data from the inventory.

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="bn" value="PP-ShopCartBF" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/sc-but-02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="no_shipping" value="2" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="Your Email Address" />
<input type="hidden" name="item_name" value="The Item Title" />
<input type="hidden" name="item_number" value="The Item ID" />
<input type="hidden" name="amount" value="The Item Price" />
<input type="hidden" name="currency_code" value="The Currency Code" />
</form>

The Solution

With 20/20 DataShed's tokens, we can put information from the database directly into a PayPal <form> in the "item_template(Default).html" file. Like this:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="bn" value="PP-ShopCartBF" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/sc-but-02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="no_shipping" value="2" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="Your Email Address" />
<input type="hidden" name="item_name" value="[fieldDisplayTitle::value]" />
<input type="hidden" name="item_number" value="[fieldItemID::value]" />
<input type="hidden" name="amount" value="[fieldListingPrice::value:currencyformat{0,2,0,0}]" />
<input type="hidden" name="currency_code" value="[fieldCulture::value:cultureformat{8}]" />
</form>

You'll notice that the code above contains four (4) of 20/20 DataShed's tokens. These are discussed below:

[fieldListingPrice::value:currencyformat{0,2,0,0}]
This token obviously produces the "Listing Price" of the item.
The ":currencyformat{}" attribute contains four numbers. That list of numbers is used to control the output of the ":value" property. Like this:
[fieldCulture::value:cultureformat{8}]
This token is used to output the three-digit currency code.
The "culture" field for each item can be different in 20/20 DataShed. This means that each item in your inventory might be a different currency! Usually that's not the case, but it's still important that we tell PayPal what currency to use in its shopping cart.
The value of the "culture" field will always be the Microsoft Windows "short name". For example, the short name for "Spanish (Spain)" is "es-es"; and the short name for "English (United States)" is "en-us".
However, the "cultureformat{}" attribute allows us to output the item's "culture" in different ways, like below:
[fieldDisplayTitle::value]
This token outputs the data from the "display_title" field. Usually this is a brief name or catch phrase which describes the item.
We have decided to use the "Display Title" as an item name. However, it's possible to use any of the tokens for this purpose. In your own business it might be more appropriate to use a different field or a combination of fields to identify the item.
[fieldItemID::value]
This token outputs the "itemID". Simple.
PayPal will use this information in the electronic receipt for the visitor. It is an easy way to reference the item on your web site.

And to clean up loose ends, the following code into the "template.html" file...this will provide visitors with an easy way to quickly view the contents of their shopping cart.

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="business" value="Your Email Address" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/view_cart.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
<input type="hidden" name="display" value="1" />
</form>

Related topics


© 2005 - 2007 20/20 Applications. All rights reserved.