ppext Event based wrapper for PayPal IPN, PDT and button manager

  1. Requirements
  2. Installation
  3. Usage
  4. Resources
  5. Change log
  6. Todo

Event based wrapper for PayPal IPN, PDT and button manager (NVP).

  • Manage buttons (PPButtonManager)
  • Process PDT events (PPPdtAction)
  • Process IPN events (PPInpAction)
  • Logging via Yii::log()

Requirements

  • Yii 1.1 or above
  • curl
  • PHP 5.3 (only PPDefaultController, which is an example, use PPDefaultLegacyController for PHP 5.2+)

Installation

  • Extract into WebRoot/protected/modules/payPal

  • Edit WebRoot/protected/config/main.php and add the following

'modules'=>array(
    ...
    'payPal'=>array(
        'env'=>'sandbox',
        'account'=>array(
            'username'=>'Your PayPal API username',
            'password'=>'Your PayPal API password',
            'signature'=>'Your PayPal API signature',
            'email'=>'Your PayPal email address',
            'identityToken'=>'Your PayPal identity token',
        ),
        'components'=>array(
            'buttonManager'=>array(
                //'class'=>'payPal.components.PPDbButtonManager'
                'class'=>'payPal.components.PPPhpButtonManager',
             ),
        ),
    ),
    ...
),
  • If you enabled PPDbButtonManager, use WebRoot/protected/modules/payPal/data/ppbm.sql to create the database schema.

Usage

  • Take a look at WebRoot/protected/modules/payPal/controllers/PPDefaultController for an example on IPN and PDT listeners (payment processing).

  • Take a look at WebRoot/protected/modules/payPal/controllers/TestController for an example on the button manager (actually just test code, but it should give you a good idea of how it works).

PPPhpButtonManager should only be used for installation scripts and similar. PPDbButtonManager can be used to dynamically create buttons at any time (including installation scripts).

Example: Creating a "Buy Now" button

$buttonManager = Yii::app()->getModule('payPal')->buttonManager;
$buttonManager->createButton("My button", array('BUTTONTYPE'=>'BUYNOW'));

Example: PDT listener (IPN listeners are pretty much identical):

public function actionPdt() {
    $pdt = new PPPdtAction($this, "pdt");
    $pdt->onRequest = array($this, "pdtRequest");
    $pdt->onSuccess = array($this, "pdtSuccess");
    $pdt->onFailure = array($this, "pdtFailure");
    $pdt->run();
}

public function pdtRequest($event) {
    // Just invoking a success event, processing done by IPN listener
    $event->sender->onSuccess($event);
}

public function pdtSuccess($event) {
    // Notify user about successfull payment
    $str = "Success<br />";
    foreach ($event->details as $k => $v)
        $str.="$k => $v<br />";
    $event->sender->controller->renderText($str);
}

public function pdtFailure($event) {
    // Notify user about failed payment
    $event->sender->controller->renderText("Failure");
}

All examples included in the source files are tested and functional in the sandbox, unless otherwise stated in example files.

Most classes and methods are documented using PHPDoc.

Resources

Forum thread

Change log

Version 0.4 (2010-11-02)
  • Moved txn_id check from PPIpnAction::run() to PPDefaultController and PPDefaultLegacyController
Version 0.3 (2010-10-29)
  • PPhpButtonManager: Changed createNewButtonModel() from public to protected
  • Implemented PPDbButtonManager
  • Renamed controllers to include PP prefix
  • Implemented PPDbButtonManager
  • Implemented PPDefaultLegacyController for PHP 5.2+
Version 0.2 (2010-10-28)
  • All IPN and PDT events are logged (success and failure)
  • Moved ipnRequest and pdtRequest from PPUtils into IPN- and PDT actions
  • Details about events (payments usually) is now stored in PPEvent::details
  • PPIpnAction and PPPdtAction cleaned up and tested
  • DefaultController (IPN and PDT example) cleaned up and tested
  • Updated documentation

Todo

  • Make 5.2+ compatible
  • Helper methods for common buttons
  • Standard payment processing methods (validating payment status, saving transactions in DB, ..)?
12 0
25 followers
3 795 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Web Service
Tags: ipn, paypal, pdt, ppext
Developed by: stianlik
Created on: Oct 28, 2010
Last updated: 12 years ago

Downloads

show all

Related Extensions