Home arrow PHP arrow Page 2 - Deploying and Implementing PayPal IPN in PHP

Import the MySQL IPN Project Tables - PHP

This is the final part of the PayPal IPN PHP script tutorial. This part will discuss the implementation and project deployment procedures for getting the PayPal IPN PHP script project up and running on your own test server.

  1. Deploying and Implementing PayPal IPN in PHP
  2. Import the MySQL IPN Project Tables
By: Codex-M
Rating: starstarstarstarstar / 4
February 01, 2011

print this article



Right click on the downloaded ipndatabasetables.zip, and then click "Extract here." You should then see three database tables which are discussed thoroughly in the third part of this tutorial series: http://www.devshed.com/c/a/PHP/Database-Tables-for-a-PayPal-IPN-PHP-Website-Payments-Application/

You are to import these tables into the MySQL database you defined in connect.php in the previous section. Let's use the SSH command line method to import these tables (you can also use phpMyAdmin, although SSH offers better protection in terms of security).

Using this method requires your server to have SSH enabled. You should consult with your hosting support. This also assumes you are using a Linux terminal or Putty in Windows (http://www.chiark.greenend.org.uk/~sgtatham/putty/ ).

Step 1. Upload these three SQL files to a temporary location in your server where you know the absolute path (e.g /home/temporary/). After uploading, log out of your server.

Step 2. Re-connect to your SSH server using either the Linux terminal or PuTTY. Configure it as follows:

Replace yourdomain.org with your own domain, as well as the port number (standard SSH port uses 22, but other web hosts may not).

If you are using a Linux terminal:

codex-m@codex-m-desktop:~$ ssh -p 22 ssh_username@yourdomain.com

You are then required to enter your SSH password.


Step 3. At the bash prompt (after a successful login):

To import customerrecords.sql (customerrecords table) to a MySQL database named databasename:

-bash-2.05b$ mysql -uMySQLUsername -pMySQLPassword -hMySQLhostname  databasename </absolute_path/to_your_SQL_files/customerrecords.sql

Replace with your own MySQL username, password, hostname and database name, as well as the absolute server path to your uploaded SQL files in step 1.

To import ipnlogs.sql (ipnlogs table) to a MySQL database:

-bash-2.05b$ mysql -uMySQLUsername -pMySQLPassword -hMySQLhostname       databasename </absolute_path/to_your_SQL_files/ipnlogs.sql

To import productstable.sql (productstable) to a MySQL database:

-bash-2.05b$ mysql -uMySQLUsername -pMySQLPassword -hMySQLhostname  databasename </absolute_path/to_your_SQL_files/productstable.sql

All of the above commands entered should not produce any error.

Final testing procedures

1. Log in to your PayPal Sandbox account here: https://developer.paypal.com/
You are required to be logged in to your Sandbox account during this entire testing process. Do not log out while the testing is going on.

2. Go to the shopping page URL: http://www.yourdomain.com/paypal_ipn_demo/
There should not be any PHP or MySQL-related errors on it. You should see two PayPal buttons for two test ebooks.

See screen shot here: http://www.php-developer.org/screenshot/shoppingpage.jpg

3. Try to make a test purchase. Suppose you want to purchase the ebook "Codex ebook." Click its "Buy Now" button.

4. You will then be taken to PayPal for payment processing. Enter your buyer email address in PayPal. Remember that in the first part of this series you created two sandbox email accounts, one for the seller and one for the buyer. Use the buyer login to purchase.

5. You are required to review your payment. Click "Pay Now" to complete the transaction. You will then see the message "Thank you for your payment." Next, you will see the "Click here to download your ebook."

See the screen shot here: http://www.php-developer.org/screenshot/thankyouforpayment.jpg

6. Click "Click here to Download your ebook." If you are not using SSL, you will see a security warning; just click "Continue." To resolve this error, you should be using https for your download URL (refer to step three in the "Configure index.php" section)

7. You are then required to enter your PayPal invoice number. PayPal sandbox emailed this to your test buyer account email. To access the invoice number, go to your PayPal Sandbox page, and then click "Test Email."

8. Under the subject, click "Notification of Payment received" addressed to your buyer email. See screen shot:


9. The email will then launch in another browser window; scroll down and look for the invoice number. See screen shot:


10.) Copy and paste this invoice number to the download page:

See screen shot: http://www.php-developer.org/screenshot/downloadpageipn.jpg


11. Enter the recaptcha code, and finally, click "Download my ebook."

A force download dialog box will then appear, asking you to download and save the purchased ebook to your computer. You can then refer to your MySQL database IPN tables (customerrecords, etc) for detailed records of the transaction. If you are having issues testing the processes above, it can relate to IPN handler script problems, such as your web host imposing limitations to your connections. You can check the logs in the ipnlogs MySQL table for troubleshooting.

Once you have successfully tested everything in your test server, you can then integrate this project into your real website shopping pages, and then use your real PayPal business account instead of the sandbox.

This means that you will replace all references in the script that go to http://www.sandbox.paypal.com/ and change them to www.paypal.com. This can be done by simply removing the word "sandbox" from the PayPal URL. Bear in mind that testing in a real PayPal environment requires real money for the transaction, so take note.

A test purchase in a real PayPal environment (not in the sandbox) is recommended to ensure that there are no technical problems that can affect customer shopping and checkout experiences on your website.

The files that need to be edited to change the references from http://www.sandbox.paypal.com/ to http://www.paypal.com/ for actual implementation of the PayPal IPN include:

1. index.php - the PayPal Button HTML code.

2. ipnhandler.php (find the following lines of code)

a) fsockopen references:

$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

b) PayPal Business email (change it from the sandbox business email to a real PayPal business account email):

if ($receiver_email=='YOUR_PAYPAL_SANDBOX_EMAIL@yahoo.com') {

>>> More PHP Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: