8.4 Using PayPal Encrypt tool
As we have already seen at chapter 7 we can generate our 'BUY NOW' buttons really easily directly from PayPal.You may have already noticed some PayPal Button generators at the web but they produce clear code (unsecure) and not encrypted. Do you remember the 'Button Encryption option' at the PayPal Create button generator seen on chapter 7?
The real problem here is the encryption and not the generation of a 'BUY NOW' button. PPEncryptGUI generates encrypted 'BUY NOW' buttons like PayPal recommends. Please note that the core of this program (PPEncrypt) is developed by PayPal itself. Let's see the needed steps to make it work correctly.
- Installing .NET framework. As said before PPEncrypt is written over the .NET framework so this framework is needed in order to run this program. If you are unsure if you have the .NET framework, just go to your WINDOWS folder and see if you have any folder called 'Microsoft.Net'. If you have a structure like this :
- Installing OpenSLL. Download and install OpenSSL Light from:
- Configuring OpenSSL. On windows go to Start -> Control Panel -> System. Hit the 'Advanced tab' and then the 'Environment Variables' button. A new form will appear with name 'Environment Variables', now, under the groupbox 'System variables' double click on 'Path'. Figure fig:78
- Generate a private key. Go to Start -> Run write 'cmd' to load the console. Write to the console :
- Generate public certificate. Always at the console write :
- Get the PayPal Public Certificate and your cert_id from PayPal. Go to paypal.com -> Profile -> Encrypted Payment Settings. Press the 'Add' button figure fig:82, in the next page hit the 'Browse' button to upload your public certificate (my-pubcert.pem) and press the 'Add' button figure fig:83.
C:\WINDOWS\Microsoft.NET\Framework\...
you already have the framework installed and the version is shown at the subfolder of the folder Framework. At windows vista .NET framework is already included. Anyway you can get the latest version of the .NET framework going to : microsoft.com/net . Make sure to download the Redistributable Package. If you are unsure or cannot find the redistributable package use Google with these keywords : 'download .net Redistributable Package'.
www.slproweb.com/products/Win32OpenSSL.html or from
www.openssl.org/related/binaries.html
fig:78 Windows Environment Variables
This should open the 'Edit System Variable' form dialog. Go to the end of the line in the 'Variable value' text box and enter a semicolon ';C:\OpenSSL\bin' and click on 'OK' 'OK' 'OK' to save the changes. Figure fig:79
fig:79 Edit System Variables
openssl genrsa -out my-prvkey.pem 1024
Please do not close the console.
openssl req -new -key my-prvkey.pem -x509 -days 999 -out my-pubcert.pem
Now you will be asked a few questions like country code, locality name etc... fill them with the correct information. Figure fig:80
fig:80 OpenSSL commandline and questions
Find the generated files my-prvkey.pem my-pubcert.pem. The figure fig:81 will help you locate the containing folder of the my-prvkey.pem my-pubcert.pem files.
fig:81 Locating the generated files by OpenSLL
fig:82 Adding a new public certificate at PayPal
fig:83 Uploading the Public Certification
Now Download the PayPal Public Certificate paypal_cert_pem.txt fig:84
fig:84 Downloading the PayPal Public Certification.
Do not forget to write down your cert_id for example AAAPAX3F6J9PD. Figure fig:85
fig:85 Finding your Cert Id
- The private key file : my-prvkey.pem.
- The public certificate file : my-pubcert.pem.
- The PayPal Public Certificate file : paypal_cert_pem.txt.
- The cert_id string : like AAAPAX3F6J9PD.
http://www.yourwebsite.com/PayPal/Code/pdthtml.php
These values are the same for every product. Now you can start adding the products by filling the attributes : Name , Id and amount. Once you have written these values just press the 'Add product' button to add the product on your product list. Continue adding your products. When you are ready press the 'Save Job' to save all the values, of your PayPal account and your product list, into a ppe file. By pressing the 'Generate Buy Now buttons' you will generate one htm for each product with name equal at the product name. With Modify and Delete buttons you can modify and delete a selected product from the product list. Please remember always to save the job. If you closed the program when you re run it you will have a blank form. Just press the load job (ppe) to obtain the last saved status. One detail here : when you press the 'Generate Buy Now buttons' the program generates a 'run.bat' file and then generates the htm files. If you are an expert you can modify the run.bat file but it is not recommended. Anyway the gurus can modify the run.bat file and then execute it to get the 'BUY NOW' buttons. All the generated files are located at the root of the 'PPEncryptGUI' folder. Figure fig:86
fig:86 PPEncrypt GUI
It is time now to test our results. Just double click at the generated htm files, these have to open with your default browser and you will see a nice 'BUY NOW' button. Figure fig:87.
Click on it to test it. The correct response of PayPal is shown on the figure fig:88. If you get errors make sure that your files my-prvkey.pem, my-pubcert.pem and paypal_cert_pem.txt are correct and the cert_id is correct too.
fig:87 PPEncrypt GUI
fig:88 Correct response from Paypal
If everything looks ok, you can open the htm file with notepad++ copy everything and paste that code at the associated product file (example : productHX0001.php) in the attribute : $Product['ButtonLink'] like we did it before (listing "Real product file productHX0001.php"). Remember that the product file (php) must have the same attributes with those located at PPEncryptGUI tool. Figure fig:89
The same fact was true with the use of PayPal, just take a look again at the figure fig:41
fig:89 Generating buttons. We must have the same attributes. In this example we have two errors.
Unfortunately on some computers PPEncrypt, the core of PPEncryptGUI, has bugs and does not generate any htm files. Even in the official forum of PayPal for developers this question seems unanswered. The best thing to do is to install and convert PPEncryptGUI on another computer. I hope that this problem will be fixed as soon as possible.