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 58 Offer Discount Coupons

figs/moderate.gif figs/hack58.gif

Reward good customers and entice new buyers with electronic coupons.

Everyone loves a sale. Customers like them because they get a bargain, and merchants like them because they increase sales. For instance, Amazon.com uses their Share the Love system to entice customers to advertise the products they've just purchased, in exchange for 10% off future purchases.

PayPal doesn't offer a built-in mechanism to process discounts, but you can set up electronic coupons for your customers with your own code. This hack provides two ways to pull it off: at the browser (a.k.a. client-side) with JavaScript, and at the server using Microsoft's Active Server Pages.

5.15.1 Accepting Coupons on the Client Side

While traditional coupons consist of slips of paper presented at the checkout counter of your local grocery store, electronic coupons are nothing more than distinct strings of numbers and letters.

This JavaScript-powered example allows a customer to specify a coupon code and then purchase an item at a discounted price:

<html>

<head>

<!-- -->

<script language = "JavaScript">

function on1Verify( )

{

1.  var orderTotal=7.95;

  var on1Value=window.document.form1.on1.value;

  window.document.form1.on1.value="";

2.  if((on1Value < 990) && (on1Value > 988))

  {

    var newTotal=orderTotal-2;

    if(newTotal < 2)newTotal = 0;

3.  window.document.form1.on1.value="$2.00";

    window.document.form1.amount.value="$" + newTotal;

  }

4.  if((on1Value) < 989 || (on1Value > 989))

  {

    window.document.WEB_ORDER_FORM.on1.value=" -";

  }

}

</script>

</head>

<body>

<b>

<form name="form1" action="https://www.paypal.com/cgi-bin/webscr"

                method="post" target="paypal">

<input type="hidden" name="cmd" value="_cart">

<input type="hidden" name="add" value="1">

<input type="hidden" value="seller@example-domain.com" name="business">

<input type="hidden" name="item_name" value="Coupon Code 1">

<input type="hidden" name="item_number" value="001">

<input type="hidden" value="Selected" name="on0">Select<BR>

<select name="os0">

<option value="Option 1" selected>Option 1

<option value="Option 2">Option 2

<option value="Option 3">Option 3

</option>

</select><BR>

Enter Coupon number:<BR>

<input type="text" name="on1" size="10" onChange="on1Verify( )">

<br><input type="hidden" value="DISCOUNT" name="os1">

Total amount due:<BR>

5.  <input type="text" name="amount" value="7.95" size="10"> 

<input type="hidden" value="http://www.example-domain.com" name="return">

<input type="hidden" value="http://www.example-domain.com" 

                name="cancel_return">

<BR>Shipping:<BR> <SELECT name="shipping">

<OPTION value="5.00" >Standard

<OPTION value="10.00" >Next Day

<OPTION value="15.00" >Over Night

</SELECT>

<input type="hidden" select_name="shipping" value=""> 

<input type="hidden" name="shipping2" value="5.00"> <BR>

Handling:<BR>

<input type="text" name="handling" value="2.00" size="10"> 

<p><input type="submit" value="Submit" name="B1">

</form></b>

</body>

</html>

Anyone who views the source of this page will be able to discover the code needed to obtain the discount. To avoid this problem, you might want to obfuscate your code [Hack #36] or use server-side coupon verification, as described later in this hack.


The normal price of the item is $7.95, as specified on lines 1 and 5. The customer enters a valid coupon code (here, the code 989 is tested on lines 2 and 4, the purchase price drops by $2.00 (line 3). Figure 5-12 shows what the form looks like.

Figure 5-12. Processing coupons with a simple HTML form and some client-side JavaScript
figs/pph_0512.gif


5.15.2 Hacking the Hack

The code in the previous section is designed to accommodate a specific range of coupon codes. As shown, the range only allows 989, but you can increase this by changing line 2 to:

if((on1Value > 5381)&&(on1Value < 5478))

and line 4 to:

if((on1Value < 5382) || (on1Value > 5477))

Doing so instructs the script to accept any coupon code between 5382 and 5473, inclusive.

5.15.3 Verifying Coupons on the Server Side

The previous solution shows how to use the browser for simple coupon processing, but for better security and more flexibility, you'll want to enable the discount at the server.

This example uses a special (presumably secret) URL to enable the discount. The URL itself serves as the coupon, and once your customer has visited this page, a discount of your choice will apply. From your customer's perspective, getting the discount price is simple:

  1. The customer receives a promotional email from you that contains the coupon.

    Never send unsolicited email messages (also known as spam) to your customers. Let customers who want to hear about your specials opt in by adding their email addresses to your mailing list.


  2. The customer clicks the coupon link, and the resulting page shows a "Thank You" or some other confirmation, followed by links to your shopping pages.

  3. All applicable prices on your site subsequently reflect the discount for this customer.

Behind the scenes, the coupon page contains a script that sets a session variable for the customer's visit. Session variables are available with many scripting languages and are easy to implement with ASP, as in this example.

First, create the coupon page, the page shown to customers when they click your coupon links. This is also where the session variable is set:

<%

'Set the session variable

        Session("discount") = "true"

%>

<h1 align="center">Thanks for using your coupon</h1>

<p>Your discount has been enabled.</p>

<%

'Redirect to storefront

Response.Redirect("http://www.wwjcd.biz/shopping/")

%>

Give the script a particularly obscure URL to prevent customers from accidentally discovering it, such as:

http://www.wwjcd.biz/discount/farcvuznutz/discount.asp

Next, modify your PayPal buttons to check for the discount session variable:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="business" value="sales@wwjcd.biz">

<input type="hidden" name="item_name" value="Jackie Chan Bobble Head">

<input type="hidden" name="item_number" value="BH-JC1">



<input type="hidden" name="no_note" value="1">

<input type="hidden" name="currency_code" value="USD">

<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif"

                border="0" name="submit" alt="Make payments with PayPal - it's fast,

                free and secure!">

<% If Session("discount") = "true" Then %>

        <input type="hidden" name="amount" value=".90">

<% Else %>

        <input type="hidden" name="amount" value="1.00">

<% End If %>

</form>

Although you can see the code that checks for the discount setting (and the setting that is being checked), your buyers will never see it. Everything between the code markers (<% and %>) is processed and subsequently removed by your web server by the time your customers view the page.

    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
    Introduction: Hacks #45-50
    Hack 45 Hack Shopping Cart Buttons
    Hack 46 Create Shopping Cart Links
    Hack 47 Specify the Size of the Shopping Cart Window
    Hack 48 Deal with Design and Layout Issues
    Hack 49 Put Both Cart Buttons in One Form
    Hack 50 Integrate a Third-Party Shopping Cart with PayPal
    Hack 51 Customize Checkout Pages
    Hack 52 Display the Merchant Transaction ID on Your Return Page
    Hack 53 Remember Your Customers
    Hack 54 Create a Dynamic Storefront
    Hack 55 Add Dynamic Storefront Details
    Hack 56 Insert Dynamic Images
    Hack 57 Build an Order-Tracking Page
    Hack 58 Offer Discount Coupons
    Hack 59 Increase Search Engine Exposure
    Hack 60 Sell Digital Goods with PayLoadz
    Chapter 6. Managing Subscriptions
    Chapter 7. IPN and PDT
    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