Developing tomorrow's applications today. Affordable web development, programming, customization, and web hosting to meet your growing business needs. www.capleswebdev.com
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:
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.
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.
Developing tomorrow's applications today. Affordable web development, programming, customization, and web hosting to meet your growing business needs. www.capleswebdev.com