Free PHP PayPal class

Download    Support forum

donate

THIS IS OLD PHP PAYPAL CLASS. IT MAY NOT WORK WITH CURRENT PAYPAL SYSTEM (NOT TESTED).
Free simple PHP class for PayPal payments with IPN (instant payment notification) validation that allows you to enable subscriptions or one-time payments. Supports adding/removing variables so you can further customize your payment (e.g enable trial period for your product), payment form output and logging.
Good implementation can be found in the directory script (payment.php & pipn.php).

Example: The payment (payment.php):

<?php 

include_once('paypal.inc.php');
$paypal = new paypal();

//optionally disable page caching by browsers
$paypal->headers_nocache(); //should be called before any output

//set the price
$paypal->price='33';

$paypal->ipn='http://www.example.com/pipn.php'//full web address to IPN script

//enable recurring payment(subscription) for every number of years
$paypal->recurring_year($r);

//OR every number of months
$paypal->recurring_month($r);

//OR every number of days
$paypal->recurring_day($r);

//OR one-time payment
$paypal->enable_payment();

//change currency code
$paypal->add('currency_code','GBP');

//your paypal email address
$paypal->add('business',PAYPAL_MAIL);

$paypal->add('item_name','Product name');
$paypal->add('item_number','Unique id');
$paypal->add('quantity',1);
$paypal->add('return',SITE_URL);
$paypal->add('cancel_return',SITE_URL);
$paypal->output_form();


The IPN script:

<?php 

include_once('paypal.inc.php');
$paypal=new paypal();

// optionally enable logging
// $paypal->log=1;
// $paypal->logfile='/absolute/path/to/logfile.txt';

//if you are dealing with subscriptions this must be called first
$paypal->ignore_type=array('subscr_signup');

if(
$paypal->validate_ipn())
{

    if(
$paypal->payment_success==1)
    {
        
//payment is successfull
        //use the item id to identify for which product the payment was made 
        
$id=intval($paypal->posted_data['item_number']);
    }
    else
    {
        
//payment not successful and/or subcsription cancelled
    
}
}
else
{
//not valid PIPN  log

}


Download
Support forum

Resources:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro
Paypal