Your IP Address: 54.80.180.41

Coupon Codes

Currently PayPal does not offer the ability to offer discount codes, or coupons. However, it is still possible to offer discounts to your customers by either using a 3rd party shopping cart that supports a feature like this, and that works with PayPal. You can find a list of 3rd party shopping carts that work with PayPal at the following link here. The other option would be to use a script that would apply the discount to the amount and then pass over that discounted amount to PayPal as the amount to charge.

The sample below is a simple script that applies a discount for things like promotions. Once you set it up you can turn on/off discounts by changing a single line of code.

The sample script here on this page would be used on small sites where all items for sale are displayed on a single page. If you have a site where your products are strung out among many pages you have to go to cookies to be able to "remember" the discount across those pages. In my client-side shopping cart I use cookies for that, but this is a simple example to demonstrate the basic concepts, only.

Many sites would like to offer something like a $5 discount, but this is difficult if the site has items that cost less than $5. To effectively offer an amount discount you need a 3rd party cart to insulate you from the customer's ability to make changes to the order once within the PayPal system.

If security is a concern then you should look into the ability to have private folders on the server you are using. The JavaScript should be put into its own file and that file then placed in a private folder. That way it cannot be read, or modified.

We start with the PayPal button factory for creating a button. You will want to make sure that you are choosing a non hosted button. This is done by un-checking the box on step 2 of the button factory that says "save button at PayPal". Then once you click create button, your HTML code will be rendered. Once on the page that contains your button code you will see a link that says "remove code protection". You will need to remove the code protection so that the HTML code is editable. Once you have the HTML code, we will need to make some modifications to the code.

To generate a non-hosted/encrypted button follow these steps:

  • Log in to your PayPal account.
  • Click on the Merchant Services Tab and select "Buy Now Button"
  • Click create a "Buy Now" button.
  • Enter your information to customize the button to your needs.
  • Click Step 2 and uncheck the "Save button at PayPal"
  • Click "Create Button."
  • Click "Remove code protection"

  • Note this is not non-hosted/encrypted code
  • Click "Select Code" to select the button code.
  • Copy and paste the button code into your own web page code.
  • Copy the JS from this example and paste it into your page just after the <body>, like is done on this page.
  • Go into every FORM that can place an order and add these things...
    • Copy the JS from this example and paste it into your page within the <head> section, like is done on this page, or into the <body> section. Only one copy of the JS is needed for any page.
    • A new named element called basedes to hold the base description of this item.
    • An event handler to the "add" button or, as is done here, an onsubmit event handler to the FORM element.


The first FORM just gives the discount with no questions. Your site would proclaim a 10% discount on all products for the next week. The pricing on the site remains the same, but a 10% discount is applied to all items ordered. The discount is set by changing the first line under the <script> tag. Setting it to zero turns the discount off.

var discnt = 0;   // no default percent discount

	The above setting requires a coupon entry to change.
		
var discnt = 10;  // percent discount to offer customers
		
	This setting gives a blanket 10% discount to everything on this page.
		

Form 1 Example

SPECIAL - for the next week a 10% discount on all items! [picture] Blah, blah. $10.00 each

Input quantity >    



A little more difficult is to use a broadcast coupon method. A Broadcast Coupon is something like putting an add in the paper that anyone may see. You give them a coupon code, and if they enter it into your site then you give them a discount. If you want to give specific people a coupon then you are going to have to do that server-side where you have the ability to remember the code for a specific individual. This is client-side where no such memory exists (people regularly delete their cookies [at least I do]).

In this example we ask for a code, and if one of the proper codes is given it is reported to you, and the discount associated with that code is applied. Perhaps you place ads in several papers, each with a different coupon code to see which paper is giving the best advertising results. For this simple example the code entered is placed into the "item_number" field so you can see it. In reality you might want to place it into the "custom" field so no one but you can see it.

Form 2 Example

Enter Coupon code [coup1] >    

[picture] Blah, blah. $20.00 each

Input quantity >    



These scripts are some I have used in the past, and have been put up on this site to help others. You are more than welcome to use any of these scripts and modify them as you need. These scripts may or may not work for you depending on your needs. If you are needing a script custome coded to meet your specific needs, feel free to EMAIL ME.

Caples Web DevelopmentDeveloping tomorrow's applications today. Affordable web development, programming, customization, and web hosting to meet your growing business needs. www.capleswebdev.com