Yii 1.1: ppext

Event based wrapper for PayPal IPN, PDT and button manager

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()


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


  • Extract into WebRoot/protected/modules/payPal

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

            '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',
  • If you enabled PPDbButtonManager, use WebRoot/protected/modules/payPal/data/ppbm.sql to create the database schema.


  • 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");
public function pdtRequest($event) {
    // Just invoking a success event, processing done by IPN listener
public function pdtSuccess($event) {
    // Notify user about successfull payment
    $str = "Success<br />";
    foreach ($event->details as $k => $v)
        $str.="$k => $v<br />";
public function pdtFailure($event) {
    // Notify user about failed payment

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.


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


  • Make 5.2+ compatible
  • Helper methods for common buttons
  • Standard payment processing methods (validating payment status, saving transactions in DB, ..)?

Total 10 comments

#14703 report it
stianlik at 2013/09/04 11:46am
Re: please give one example

There is an example on the on this page (see Usage), and included in the extension, additionally you can check out the forum thread.

Note that the purpose of ppext is to make PayPal interaction more convenient, you need to understand the PayPal API to use the extension efficiently. If you only need a simple BuyNow-button, you can probably find a simpler extension, for that purpose only.

#14698 report it
bvpk at 2013/09/04 04:06am
please give one example

how to use the in our application . successfully installed but how to use the button

#10132 report it
jiaming at 2012/10/05 02:20pm
Thanks for your great contribution.

If i get this extension right, this can verify the transaction is successfully or not immediately by using IPN or PDT.

Can you give a example about IPN? Which way is faster? I want to confirm the payment as soon as possible since we have a balance system. if payment is processed successfully, we need to add the user's balance asap.

Thanks so much!

#5394 report it
stianlik at 2011/10/09 11:45am
RE: Trustmanager Concept

Thank you for the link tonydspaniard, I will definitely look into it. As of now PPExt do not verify SSL certificates due to a quick fix: forum post #36.

#5384 report it
Antonio Ramirez at 2011/10/08 03:22pm
TrustManager Concept

I am currently developing a library and found something that could be useful info for yours: http://artur.ejsmont.org/blog/content/how-to-properly-secure-remote-api-calls-from-php-application

Related to TrustManager Concept

#2030 report it
stianlik at 2010/11/03 08:14am
RE: PHP 5.2.x compatibility

DefaultController is the only component that requires PHP 5.3 (and this is just an example), I have implemented DefaultLegacyController to support PHP 5.2+. To keep it completely 5.2+ compatible DefaultController will be replaced by DefaultLegacyController.

#2028 report it
makro at 2010/11/03 07:03am
PHP 5.2.x compatibility

I agree with Say_Ten

#2004 report it
stianlik at 2010/10/29 05:06am
Re: Re: Example Requirements
public function DefaultController

in the previous reply should be changed to

public function pdt()
#2003 report it
stianlik at 2010/10/29 05:03am
Re: Re: Example Requirements

Thank you for the heads up, I have updated the requirements.

For those who doesn't have access to a host running PHP 5.3, the example should work if you first create the methods onSuccess, onFailure and onRequest and refer to them in the pdt/ipn actions:

public function DefaultController {
    $pdt->onRequest = array($this,"requestHandler");
public function requestHandler($event) {

The module is only tested using PHP 5.3.

#2002 report it
Say_Ten at 2010/10/29 04:38am
Re: Example Requirements

The examples contain anonymous functions, which require PHP 5.3+. I only mention as the framework is currently PHP 5.2+ compatible and not all hosts are on 5.3, believe it or not.

Leave a comment

Please to leave your comment.

Create extension