PPExt - PayPal extension

Thanks very much for creating this extension. I am still testing it and am having some problems…

I have followed all advice from the extensions page and this thread regarding setting up the extension with my PayPal sandbox account and when trying to use the test and legacy controllers I get errors that seem like my credentials are invalid.

For example i execute /payPal/PPTest/create/ and get ‘boolean false’ as the response. The log says:

Failed create button

Request: BUTTONTYPE=BUYNOW&METHOD=BMCreateButton

Similar errors are produced for all actions of the test and legacy controllers.

Here is my log of what I have done so far:




-sandbox:

	create account preconfigured

	select country, seller account, login name and password etc.

	choose API credentials to get: 

		-API Username

		-API Password

		-Signature

		alternatively way to access the above: 

			-login to account

			-choose: profile -> API Access -> View API Signature

	login to account:

		-get identityToken: under profile look for Secure Merchant Account ID

		-enable IPN and set url: profile -> Instant Payment Notification Preferences 

	

			

	

-setup yii extension ppext:

	create yii project using yii version 1.1.6

	copy PayPal directory (ppext module version 0.4) to modules directory

	add the following to config/main.php:

	

	'modules'=>array(

		'payPal'=>array(

			'env'=>'sandbox',

			'account'=>array(

				'username'=>'API Username',

				'password'=>'API Password',

				'signature'=>'signature',

				'email'=>'account email address',

				'identityToken'=>'Secure Merchant Account ID'

			),

			'components'=>array(

				'buttonManager'=>array(

					'class'=>'payPal.components.PPPhpButtonManager'

				)

			)

		)

	)



Any suggestions?

From what you’ve written, it seems like you’re on the right track, I assume you have replaced “API Username”, etc. by your actual API username, etc.? I don’t see any apparent errors, but I’ll try to give you some advice on what might case the errors.

The message, "Failed create button", appears if PPUtils::nvpRequest($nvp) has failed. This can occur if your server were unable to connect to PayPal (make sure curl is installed and enabled), in that case you will get no further messages. It can also appear if you received a failure-response from PayPal, in that case the log will also include a message "NVP request failed …", and can be caused of authentication problems, etc.

I’ll probably be able to give you some better advice if you upload protected/runtime/application.log.

Yep, have replaced ‘API Username’ etc. with the correct details and curl is installed and functioning.

If I visit /payPal/PPTest/create/ after clearing application.log this is what I get:




2011/01/27 17:29:22 [error] [payPal.components.PPButtonManager] Failed create button

Request: BUTTONTYPE=BUYNOW&METHOD=BMCreateButton

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/components/PPButtonManager.php (240)

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/components/PPButtonManager.php (60)

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/controllers/PPTestController.php (22)



And thats it :-\

Alright, it seems like the http request is failing (could probably use some more fine-grained logging there). Could you try editing .../payPal/components/PPUtils.php as follows, and post the result?




// Already in PPUtils (line 209)

$response = PPUtils::httpGet(self::getUrl(self::NVP), $getStr, true);


// Insert this to get more logging

if ($response['status'] == false)

    Yii::log($response['error_msg'],'error','payPal.components.PPUtils');



This is what I get with the additional logging:




2011/01/27 19:34:13 [error] [payPal.components.PPUtils] SSL certificate problem, verify that the CA cert is OK. Details:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/components/PPUtils.php (212)

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/components/PPButtonManager.php (59)

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/controllers/PPTestController.php (22)

2011/01/27 19:34:13 [error] [payPal.components.PPButtonManager] Failed create button

Request: BUTTONTYPE=BUYNOW&METHOD=BMCreateButton

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/components/PPButtonManager.php (240)

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/components/PPButtonManager.php (60)

in /Users/gazbond/PHP Projects/test-ppext/protected/modules/payPal/controllers/PPTestController.php (22)



EDIT: httpPost already has this option enabled, you could copy line 147 and 148

below line 88.

Seems like cURL does not trust PayPals SSL certificate, could you try to add the following in payPal/components/PPUtils.php?




// Add this after line 88 (httpGet) and after line 143 (httpPost)

// This will instruct cURL to accept any SSL certificate, be aware of the security risk here (more info in link below)

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);



If this works you should tell cURL to trust PayPals certificate:

"…by default, cURL is setup to not trust any CAs, thus it won’t trust any web server’s certificate" - Usin cUrl in PHP to access HTTPS

Many thanks that did the trick ;)

Hello again, I have been trying use PayPal PDT with your extension.

After enabling PDT in my PayPal profile I am given another identity token, where do I use this (PDT action currently fails every time, I assume this is because I’m not using this new token)?

Also, if I’m using IPN and PDT can I assume that if I receive a successful PDT request that I can ignore any subsequent IPN request (sorry if this is covered in PayPal’s docs, but can’t stand PayPal’s docs)?

OK silly me, the new identity token I was asking about should have been added to the ppext module config, I was using Secure Merchant Account ID instead!

Yes, you can ignore any subsequent IPN request with the same transaction ID, but you should always process payments using IPN, PDTs main purpose is to give users a confirmation screen (you may miss completed payments if you’re only receiving PDT requests).

EDIT: Remember to acknowledge all IPN messages.

"To handle the possibility of transmission and receipt delays or failures, the IPN message service implements a retry mechanism that resends messages at various intervals until you acknowledge that the message has successfully been received" - PayPal

Many thanks :)

Hmmn. I’ve followed the tips on this topic carefully and seems like my app is connecting to the payPal, but in the application.log it says:




"Request:BUTTONTYPE=BUYNOW&L_BUTTONVAR0=currency_code%3DUSD&L_BUTTONVAR1=item_name%3DMy+button&L_BUTTONVAR2=amount%3D200.00&METHOD=BMCreateButton&VERSION=63.0&USER=me_1302527800_biz_api1.jeresalonen.com&PWD=sukulaiset%21&SIGNATURE=Az6sXk1Fqkbak9xQZdjPvoIKwlafAgSp34fFDEuSi0rR9Ttf0QshkQGg

Response:TIMESTAMP=2011-04-11T13:32:09Z&CORRELATIONID=e5a9a0d843ae6&ACK=Failure&VERSION=63.0&BUILD=1824201&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Security error&L_LONGMESSAGE0=Security header is not valid&L_SEVERITYCODE0=Error"



Any ideas what’s causing this?

And thanks for the extension!

Your app is connecting to PayPal and receiving an error message.

Seems like you are using the wrong credentials, I tested with the form posted at https://www.x.com/thread/43931 (remember to change action to sandbox if you’re using the form).

hi all,

i am new to Yii, its really great. i did my first web app, and everything looks great and in place, what i want is to implement a recurring billing for customers, every month. can anybody recommend and extension, or a way to do so using Paypal. if someone can provide a step by step, it will be really great.

Thanks in advance.

Hello

Latest version can be downloaded from:

http://www.yiiframework.com/extension/ppext/

EDIT: The first version (ppext.tar.gz / ppext.zip in this post) has faulty IPN-code,

please download from the url above.

I am developing an event based PayPal extension for Yii, and would like to know it there is any interest in this? Feedback and feature requests are very welcome.

Features so far:

  • Button manager (you specify settings using an array of NVP-values)

  • PDT handler

  • IPN handler

  • Logging via Yii::log()

EXAMPLE USAGE

PDT- and IPN listeners (see src-code for a better example, including some payment processing)




class MinimalController extends Controller

{

	public function actionPdt() {

		$pdt = new PPPdtAction($this, "pdt");


                // Process payment

		$pdt->onRequest = function($event) {

			$this->onSuccess($event);

		};


                // Notify user on success

		$pdt->onSuccess = function($event) {

			$event->sender->controller->renderText("Success");

		};


                // Notify user on failure

		$pdt->onFailure = function($event) {

			$event->sender->controller->renderText("Failure");

		};


		$pdt->run();

	}


	public function actionIpn() {

		$ipn = new PPIpnAction($this,"ipn");


                // Process payment

		$ipn->onRequest = function($event) {

			$event->setMsg("Received payment.");

			$ipn->onSuccess($event);

		};


                // Log success

		$ipn->onSuccess = function($event) {

			Yii::log($event->msg, "info", "payPal.controllers.DefaultController");

		};


                // Log failure

		$ipn->onFailure = function($event) {

			Yii::log($event->msg, "error", "payPal.controller.DefaultController");

		};


		$ipn->run();

	}

}



Button Manager - Creating a buy now button




$this->bm = Yii::app()->getModule('payPal')->buttonManager;

$this->bm->createButton($name, array('BUTTONTYPE'=>'BUYNOW'));



Installation instructions:

  1. Extract the file into WebRoot/modules/payPal

  2. Open WebRoot/modules/payPal/PayPalModule.php for further instructions

[/quote]

Hello,

i have download paypal extension in yii framework site.

but it not run this file also extract in module folder.

i also config/main

‘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',


         ),


    ),


),

but error is…

Error 404

Unable to resolve the request "paypal".

Site tree

but it is not working.

give reply as soon as possible.

Hardik Chavda

(PHP developer)

thank you.

I have an error when i’m trying to use PPTestController.php and i don’t understand how to solve this error. Someone have tips for solve it?


CException


Property "PayPalModule.buttonManager" is not defined.


/usr/local/apache2/htdocs/framework/base/CModule.php(88)


076     /**

077      * Getter magic method.

078      * This method is overridden to support accessing application components

079      * like reading module properties.

080      * @param string $name application component or property name

081      * @return mixed the named property value

082      */

083     public function __get($name)

084     {

085         if($this->hasComponent($name))

086             return $this->getComponent($name);

087         else

088             return parent::__get($name);

089     }

090 

091     /**

092      * Checks if a property value is null.

093      * This method overrides the parent implementation by checking

094      * if the named application component is loaded.

095      * @param string $name the property name or the event name

096      * @return boolean whether the property value is null

097      */

098     public function __isset($name)

099     {

100         if($this->hasComponent($name))

To do this, you need two things:

  1. Subscribe form

  2. IPN listener

It is possible to use PPExt for both, creating the subscribe form using the button manager and

PPIpnAction for receiving IPN notifications (i.e. the IPN listener). Or, you can just create

an ipn action and a form manually. I prefer to create the form manually, and use PPExt for the listener.

The subscription form could look something like this:




	<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">

		<input type="hidden" name="cmd" value="_xclick-subscriptions">


		<!-- IPN and PDT URLs -->

		<input type="hidden" name="notify_url" value="ROUTE-TO-YOUR-IPN-LISTENER" />

		<input type="hidden" name="return" value="ROUTE-TO-YOUR-PAYMENT-CONFIRMATION-PAGE" />

		<input type="hidden" name="rm" value="0" />


		<!-- Specify details about receiver, and customer -->

		<input type="hidden" name="business" value="YOUR-PAYPAL-EMAIL" />

		<input type="hidden" name="custom" value="PASSTHROUGH-VARIABLE" />


		<!-- Specify details about the item that buyers will purchase. -->

		<input type="hidden" name="item_name" value="YOUR-PRODUCT-NAME" />

		<input type="hidden" name="currency_code" value="USD" />


		<input type="hidden" name="no_shipping" value="1" />

		<input type="hidden" name="no_note" value="1" />

		<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">

		<input type="hidden" name="a3" value="YOUR-PRICE-PER-MONTH">

		<input type="hidden" name="p3" value="1">

		<input type="hidden" name="t3" value="M">

		<input type="hidden" name="src" value="1">

		<input type="hidden" name="sra" value="1">

	</form>



For the IPN listener, take a look at the PPExt examples. You need to process subscr_signup and subscr_eot events for

a minimal subscription service (and you should consider other subscr-events as well, ipn variables described at PayPal).

What are you trying to achieve? You need to create a controller, and an action to

use the extension. If you’re trying to access the example controller, use

WEBROOT/payPal/pPDefault (case sensitive).

The error occurs at the following statement (in PPTestController):


$this->bm = Yii::app()->getModule('payPal')->buttonManager;

The error message says that you are trying to access a property that does not exist.

This property should be attached to the module by adding this to your configuration (as noted in

the installation).


 

... PayPal module  ..

'components'=>array(

            'buttonManager'=>array(

                //'class'=>'payPal.components.PPDbButtonManager'

                'class'=>'payPal.components.PPPhpButtonManager',

             ),

       ),

...



can any one help me why i am not getting the paypal buynow button

i did all the process that is mentioned above during different discussion. I USE the following code to create the button

<?php

                    &#036;buttonManager = Yii::app()-&gt;getModule('payPal')-&gt;buttonManager;


                    &#036;nvp = array(


                            'BUTTONTYPE'=&gt;'BUYNOW',


                            'L_BUTTONVAR0'=&gt;'currency_code=USD',


                            'L_BUTTONVAR1'=&gt;'item_name=My button',


                            'L_BUTTONVAR2'=&gt;'amount=20.00',


                    );


                   &#036;buttonManager-&gt;createButton('My button', &#036;nvp);


            ?&gt;

it first call the create button manager after making object of button manager class

the createbutton check response and if it is true then it will proceed otherwise return false

i get success in ACK variable but still not getting the button

what else i have to do to make it possible please help me fast asap thanka