Class PaypalIPN

Description

*****************************************************************************

PHP Paypal IPN Integration Class ****************************************************************************** Author: Micah Carrick Email: email@micahcarrick.com Website: http://www.micahcarrick.com

File: paypal.class.php Version: 1.3.0 Copyright: (c) 2005 - Micah Carrick You are free to use, distribute, and modify this software under the terms of the GNU General Public License. See the included license.txt file.

****************************************************************************** VERION HISTORY: v1.3.0 [10.10.2005] - Fixed it so that single quotes are handled the right way rather than simple stripping them. This was needed because the user could still put in quotes.

v1.2.1 [06.05.2005] - Fixed typo from previous fix :)

v1.2.0 [05.31.2005] - Added the optional ability to remove all quotes from the paypal posts. The IPN will come back invalid sometimes when quotes are used in certian fields.

v1.1.0 [05.15.2005] - Revised the form output in the submit_paypal_post method to allow non-javascript capable browsers to provide a means of manual form submission.

v1.0.0 [04.16.2005] - Initial Version

****************************************************************************** DESCRIPTION:

NOTE: See www.micahcarrick.com for the most recent version of this class along with any applicable sample files and other documentaion.

This file provides a neat and simple method to interface with paypal and The paypal Instant Payment Notification (IPN) interface. This file is NOT intended to make the paypal integration "plug 'n' play". It still requires the developer (that should be you) to understand the paypal process and know the variables you want/need to pass to paypal to achieve what you want.

This class handles the submission of an order to paypal aswell as the processing an Instant Payment Notification.

This code is based on that of the php-toolkit from paypal. I've taken the basic principals and put it in to a class so that it is a little easier--at least for me--to use. The php-toolkit can be downloaded from http://sourceforge.net/projects/paypal.

To submit an order to paypal, have your order form POST to a file with:

$p = new paypal_class; $p->add_field('business', 'somebody@domain.com'); $p->add_field('first_name', $_POST['first_name']); ... (add all your fields in the same manor) $p->submit_paypal_post();

To process an IPN, have your IPN processing file contain:

$p = new paypal_class; if ($p->validate_ipn()) { ... (IPN is verified. Details are in the ipn_data() array) }

In case you are new to paypal, here is some information to help you:

  1. Download and read the Merchant User Manual and Integration Guide from http://www.paypal.com/en_US/pdf/integration_guide.pdf. This gives you all the information you need including the fields you can pass to paypal (using add_field() with this class) aswell as all the fields that are returned in an IPN post (stored in the ipn_data() array in this class). It also diagrams the entire transaction process.
2. Create a "sandbox" account for a buyer and a seller. This is just a test account(s) that allow you to test your site from both the seller and buyer perspective. The instructions for this is available at https://developer.paypal.com/ as well as a great forum where you can ask all your paypal integration questions. Make sure you follow all the directions in setting up a sandbox test environment, including the addition of fake bank accounts and credit cards.

******************************************************************************

Located in /model/paypalipn.class.php (line 110)


	
			
Variable Summary
mixed $fields
mixed $ipn_data
mixed $ipn_log
mixed $last_error
Method Summary
PaypalIPN __construct ()
void add_field ( $field,  $value)
void dump_fields ()
void log_ipn_results ( $success)
void validate_ipn ()
void __toString ()
Variables
mixed $fields = array() (line 120)
mixed $ipn_data = array() (line 118)
mixed $ipn_log (line 114)
mixed $ipn_log_file (line 116)
mixed $ipn_response (line 117)
mixed $last_error (line 112)
Methods
Constructor __construct (line 123)
PaypalIPN __construct ()
add_field (line 144)
void add_field ( $field,  $value)
  • $field
  • $value
dump_fields (line 287)
void dump_fields ()
log_ipn_results (line 259)
void log_ipn_results ( $success)
  • $success
submit_paypal_post (line 153)
void submit_paypal_post ()
validate_ipn (line 198)
void validate_ipn ()
__toString (line 187)
void __toString ()

Documentation generated on Sun, 20 Sep 2009 02:21:24 -0700 by phpDocumentor 1.4.1