How to create dynamic Encrypted Website Payments (EWP) PayPal buttons

AID: 198
  • Status: Published

4820 points

  • By
  • TypeGeneral
  • Posted on2008-11-20 at 17:38:25
Awards
  • Community Pick
If you want to sell something on your website, perhaps something like a personalized kid's storybook, you can add a PayPal buy-button that will send the user to PayPal to make a payment to your PayPal account. You will get an email and then you can create and send the book to the buyer.

The Html code that makes up the button (created manually or from the PayPal button factory) contains things like your PayPal account email, the item description and price and perhaps a few other parameters. However, someone knowledgeable could view the source of your page or save the Html from the browser, change the price and then click the modified button and you will receive the order with a lower payment. Maybe you will notice it but if you get lots of orders for various items, it may go unnoticed until after you send the book.

The solution is to use PayPal's Encrypted Website Payments (EWP) buttons. This can be done by the button factory and you can set a flag in the profile to only allow encrypted buttons to be used on your site. People will no longer be able to modify your buttons in any way. All the parameters that make up the button are encrypted into one string of characters and that string is sent as a single parameter to PayPal when the button is clicked. When created by the factory, PayPal knows how to decrypt what it encrypted in the first place.

However, what if you want to dynamically generate your buy-buttons in your code? You can create the parameters as you need on the fly and use them unencrypted but if you want to encrypt them, you can't use the factory. For example, the personalized book's item description could be "Billy Jones and the Magic Pancake" which will display when the buyer enters PayPal to pay. Dynamic buttons are also useful when you have a database with lots of items. Once you create the set of parameters for the button, you can then run the string through an encryption routine and use the encrypted string in your buy button. The PayPal site explains how to do this (http://www.paypal.com/IntegrationCenter/ic_button-encryption.html#Encryptbuttonsdynamically).

There are several steps to do this as discussed in the link above:

1

Obtain a private key and public certificate

You use your private key to decrypt something encrypted by your public cert. Public certs are used for encryption and authentication.



2

Upload your public cert to PayPal

You then give away your public certificate to anyone that needs to authenticate that you are you or encrypt data to send to you. In this case, you upload your public cert to PayPal. Actually, PayPal does not need to send you anything encrypted so they mainly need your public cert for authentication. There are other non-PayPal uses of this private key/public cert pair like encrypted email but I will discuss that in a future posting.



3

Downloading PayPal's public cert

PayPal has two certs, one for the live PayPal site and one for the PayPal sandbox (or beta sandbox). You use PayPal's cert to encrypt the buy-button parameters. PayPal provides links for you do download their certs. Certs are created with an expiration date. In PayPal's case, their certs will expire in 2035.



4

Set your PayPal profile to only allow encrypted buttons.

Do this by logging on to your PayPal account and click on Profile and then Encrypted Payments



For testing purposes, I have created a simple tool to do steps 1 and 3 (http://www.webguild.com/PayPal.aspx). This will allow you to create your private key, public cert and have both PayPal public certs and provide them to you in a zip file. Once you have your development working, you can then go through the steps to recreate your key and cert and re-upload to PayPal but you will have to install OpenSSL on your PC (http://www.openssl.org/). This way you know you are the only one that has your private key. Using the private key from my tool in production will certainly work but it did originate from my computer.
 
GetCert.jpg
  • 72 KB
  • GetCert
GetCert


Click the Buy Now and after some seconds, if you selected the Free cert, a link will display to download the zip file and if you selected a longer expiration date, you will first pay through PayPal and then return to click the zip download. This is the file:

CertZip.jpg
  • 72 KB
  • CertZip
CertZip


The image shows the two PayPal public certs, the Pkcs12.p12 file, your private key (keep this secure) and your public cert (to give away). The Readme.txt file has some hints and information on the OpenSSL commands used to create these files. The p12 file is used by your code that generates your encrypted buttons. This file also should be kept secure since it contains both your private key and public cert.

The tool to create your private key and public cert is at http://www.webguild.com/PayPal.aspx (click the Certs and Keys tab). This page actually uses a PayPal buy button that uses a dynamic EWP button if you select the non-free option. The item name and price is encrypted and you will notice the personalized item name when you arrive on the PayPal site.

- Gary Davis
Certified PayPal Developer
    Asked On
    2008-11-20 at 17:38:25ID198
    Tags

    PayPal

    ,

    EWP

    ,

    Encrypted Website Payments

    ,

    Webguild

    Topic

    Miscellaneous Programming

    Views
    3538

    Comments

    Expert Comment

    by: jennhp on 2010-03-01 at 13:23:52ID: 10262

    I'm helping a friend out with her website and one of the things she's asked me to do is work on her PayPal settings.  I had no idea that someone could change the price of a product if they knew HTML code. Thanks for the heads up!

    Add your Comment

    Please Sign up or Log in to comment on this article.

    Join Experts Exchange Today

    Gain Access to all our Tech Resources

    Get personalized answers

    Ask unlimited questions

    Access Proven Solutions

    Search 3.2 million solutions

    Read In-Depth How-To Guides

    1000+ articles, demos, & tips

    Watch Step by Step Tutorials

    Learn direct from top tech pros

    And Much More!

    Your complete tech resource

    See Plans and Pricing

    30-day free trial. Register in 60 seconds.

    Loading Advertisement...

    Top Misc Programming Experts

    1. TommySzalapski

      70,164

      Master

      0 points yesterday

      Profile
      Rank: Genius
    2. CodeCruiser

      54,882

      Master

      0 points yesterday

      Profile
      Rank: Genius
    3. sarabande

      39,518

      0 points yesterday

      Profile
      Rank: Sage
    4. billprew

      31,992

      0 points yesterday

      Profile
      Rank: Genius
    5. for_yan

      31,100

      0 points yesterday

      Profile
      Rank: Genius
    6. ozo

      23,940

      0 points yesterday

      Profile
      Rank: Savant
    7. mccarl

      22,814

      0 points yesterday

      Profile
      Rank: Wizard
    8. Idle_Mind

      22,600

      0 points yesterday

      Profile
      Rank: Savant
    9. kaufmed

      22,004

      0 points yesterday

      Profile
      Rank: Genius
    10. jkr

      20,068

      0 points yesterday

      Profile
      Rank: Savant
    11. MartinLiss

      19,900

      0 points yesterday

      Profile
      Rank: Wizard
    12. chris_bottomley

      17,700

      0 points yesterday

      Profile
      Rank: Genius
    13. RobSampson

      16,900

      0 points yesterday

      Profile
      Rank: Genius
    14. mlmcc

      16,300

      0 points yesterday

      Profile
      Rank: Savant
    15. Ray_Paseur

      15,500

      0 points yesterday

      Profile
      Rank: Savant
    16. dlmille

      15,464

      0 points yesterday

      Profile
      Rank: Genius
    17. Zoppo

      15,350

      0 points yesterday

      Profile
      Rank: Genius
    18. CEHJ

      15,163

      0 points yesterday

      Profile
      Rank: Savant
    19. DaveBaldwin

      15,064

      0 points yesterday

      Profile
      Rank: Genius
    20. Infinity08

      14,768

      0 points yesterday

      Profile
      Rank: Genius
    21. sdstuber

      14,481

      0 points yesterday

      Profile
      Rank: Genius
    22. JamesBurger

      14,268

      0 points yesterday

      Profile
      Rank: Sage
    23. paultomasi

      13,896

      0 points yesterday

      Profile
      Rank: Master
    24. TheLearnedOne

      13,800

      0 points yesterday

      Profile
      Rank: Savant
    25. pepr

      12,800

      0 points yesterday

      Profile
      Rank: Genius

    Hall Of Fame