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 ¶
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, ..)?
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.
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) { $event->sender->onSuccess($event); }
The module is only tested using PHP 5.3.
Re: Re: Example Requirements
public function DefaultController
in the previous reply should be changed to
public function pdt()
PHP 5.2.x compatibility
I agree with Say_Ten
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.
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
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.
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!
please give one example
how to use the in our application . successfully installed but how to use the button
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.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.