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:
- She's tired of making all her web pages manually.
- She explained to us that she already sells her sheet-music online by simply adding PayPal buttons to her web pages. This is important to note: she already has a PayPal account and was already quite comfortable with the way PayPal's shopping cart and checkout process works. She didn't mind that the shopping cart wasn't "on her own web site"; in fact she liked PayPal's simplicity and trusted that PayPal's system was better than anything she could buy.
- She's looked for "Shopping Cart" software products but found that either they're not flexible enough, or they're very expensive, or they seemed too complicated and she was quite put off by all the talk about "Payment Gateways", SSL, "Merchant Accounts". Remember, her primary goals were to:
- manage her inventory online (in a database instead of having to do it manually).
- and automatically put PayPal buttons with her items (nothing complicated...just simple).
The Process
- The PayPal buttons are created on a web page with a <form> tag.
- The <form> contains all the necessary information and when a visitor clicks on the "submit" button, they are directed to the PayPal web site.
- Your visitor can add as many items as they want to PayPal's shopping cart. Each time they click on a PayPal button the new item is added to their cart and they can then return to your web site and continue shopping.
- When the visitor is finished selecting the items they want, they can go to PayPal's "Check Out" counter. PayPal's "Check Out" process will ask the visitor for their name, email address, and shipping address and will calculate approximate shipping costs and can also calculate taxes for you if you've configured your PayPal account to do so.
- The visitor then pays with their credit card (or various other options) and the money is deposited into your PayPal account. PayPal of course takes a small fee and a percentage of the total sale, but it's a small price to pay (in fact it's one of the smallest prices to pay and that's the reason PayPal's service has become so popular).
- Then, you can send the shipment to the customer and everybody's happy!
- In short...it's one of the easiest, cheapest, and most secure ways to enable e-Commerce on your web site.
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:
- The first number (0): Indicates that the number should be printed without a currency symbol. PayPal will complain if you send a number like $1.00 -- instead PayPal does not want to see the dollar sign.
- The second number (2): Indicates the number of digits after the decimal. PayPal wants two (2) decimal places -- even if they're just zeros!
- The third number (0): Indicates that the number should not use cultural formats. In other words, PayPal's web site will complain if you send a number like 1.234,00 (which is valid in many countries but not in PayPal's home, the United States). Instead, the price will be written to the <form> without a grouping-digit and with a decimal "point" -- the way PayPal likes it.
- The fourth number (0): Indicates that the number should not include any HTML code. 20/20 DataShed usually writes the price to the web page within a <span> tag, but PayPal just wants the number.
- [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:
- :cultureformat{1} = "Dutch (Belgium)"
- :cultureformat{2} = "nl-be"
- :cultureformat{5} = "Nederlands (België)"
- :cultureformat{7} = "Euro"
- :cultureformat{8} = "EUR" (This is the three-digit currency code that is PayPal-friendly)
- [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>

Send Feedback