Home arrow PHP arrow Deploying and Implementing PayPal IPN in PHP

Deploying and Implementing PayPal IPN in 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The server requirements are as follows:

  • Apache web server

  • At least PHP 5

  • At least MySQL 5

  • Linux/Unix operating system

Downloading project files and configuring connect.php

To implement this PayPal IPN PHP project on your own server, follow the procedures below:

1. Download the PHP project files here: http://www.php-developer.org/wp-content/uploads/scripts/paypal_ipn_demo.zip

2. Download the MySQL IPN database tables here: http://www.php-developer.org/wp-content/uploads/scripts/ipndatabasetables.zip

3. Right click on paypal_ipn_demo.zip, and then click "Extract here."

4. Go inside the paypal_ipn_demo folder, and then open "connect.php." Add your MySQL database login credentials (username, password, hostname, database name) on connect.php. This is the database that you will use for the PayPal IPN project. Save connect.php to implement your changes.

Configure customerdownload.php

Open "customerdownload.php" inside the paypal_ipn_demo folder. This is the download page where the customer inputs the invoice number after successfully paying with PayPal. Make the following changes:

1. Find this line:

$publickey = "YOUR_RECAPTCHA_PUBLIC_KEY";

Replace it with your own recaptcha public key. If you do not have recaptcha public and private keys, you can download it here: http://www.google.com/recaptcha  

2. Find this line: 

$privatekey = "YOUR_RECAPTCHA_PRIVATE_KEY";

Replace it with your own recaptcha private key.

3. Find this line:

include '/YOUR/ABSOLUTE/SERVER_PATH_NAME/paypal_ipn_demo/connect.php';

Replace /YOUR/ABSOLUTE/SERVER_PATH_NAME with your own server path name. Read the following tutorial for details on how to get the absolute server path: http://www.php-developer.org/how-to-get-the-absolute-server-path-name-of-an-executing-script-in-php/

4. Find this line:

header('Content-Disposition: attachment; filename="http://www.yourdomain.com/paypal_ipn_demo/ebookdownloads/'.$filename.'"');

Replace http://www.yourdomain.com with your own website domain name. 

5. Find this line:

readfile("/YOUR/ABSOLUTE/SERVER_PATH_NAME/paypal_ipn_demo/ebookdownloads/$filename"); 

Replace it with your own absolute server path. Save customerdownload.php to implement your changes.

Configure index.php

Open the index.php file inside the paypal_ipn_demo folder. This is the shopping page in your website, where the customer shops for digital products. If they are interested in purchasing your products, they will click the PayPal Buy Now buttons. Make the following changes:

1. Find these lines of code:

include '/YOUR/ABSOLUTE/SERVER_PATH_NAME/paypal_ipn_demo/connect.php';
include '/YOUR/ABSOLUTE/SERVER_PATH_NAME/paypal_ipn_demo/invoicenumbergenerator.php';

Replace with your own absolute server path.

2. For the two PayPal BuyNow HTML button codes (for two ebooks: "Codex ebook" and "How to behave like a child"), find this code:

<input type="hidden" name="business" value="YOUR_PAYPAL_SECURE_MERCHANT_ACCOUNT_ID">

Replace YOUR_PAYPAL_SECURE_MERCHANT_ACCOUNT_ID with your own ID. To determine your secure merchant account ID, follow the steps below:

 
3. Again, for the two PayPal BuyNow HTML button codes, find these lines of code:

<input type="hidden" name="return" value="http://www.yourdomain.com/paypal_ipn_demo/customerdownload.php">

<input type="hidden" name="cancel_return" value="http://www.yourdomain.com/paypal_ipn_demo/">

Replace http://www.yourdomain.com with your domain name. You should be using https/SSL secure protocol for your download page to avoid any "unsecure mode" errors experienced by your customers from PayPal to your download page. Example, it will look like this: https://www.example.com/paypal_ipn_demo/customerdownload.php  

Configure ipnhandler.php and upload the Paypal_IPN_demo folder 

Open ipnhander.php inside the paypal_ipn_demo folder. This is your actual IPN handler script, which will receive and transmit the IPN message between your test server and PayPal.

1. Find this line and replace it with your own absolute server path:
include '/YOUR/ABSOLUTE/SERVER_PATH_NAME/paypal_ipn_demo/connect.php';

2.) Find this code: $receiver_email=='YOUR_PAYPAL_SANDBOX_EMAIL@yahoo.com'
Replace YOUR_PAYPAL_SANDBOX_EMAIL@yahoo.com with your own PayPal Sandbox business email address. For example: codex__1293512831_biz@yahoo.com

Your PayPal sandbox business email is easy to spot, because of the phrase "biz" within the email address. 

That's it. You have completely configured all of the required PHP files in the PayPal IPN project. These files do NOT need to be configured, as they are included PHP files:

  • invoicenumbergenerator.php

  • is_email.php

  • recaptchalib.php

  • PDF files under ebookdownloads, because they are sample/test digital ebook products.

3. Upload the entire paypal_ipn_demo folder (that contains the configured scripts discussed previously as well as included PHP files) to the root directory of your website. For example, if your website is http://www.example.com/, the paypal_ipn_demo shopping page can be viewed in this URL: http://www.example.com/paypal_ipn_demo/ . However, do not yet open this page in the browser, as you still need to configure the MySQL database.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: