CodeIgniter Forums

Full Version: Trouble converting Paypal library to CI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]tagawa[/eluser]
Hi. I really like Micah's revised Paypal IPN library here:
https://github.com/Quixotix/PHP-PayPal-IPN

and am trying to convert it to a CI class. I can get the original library to work, but when I try out my controller with the Paypal sandbox test tool I get "IPN delivery failed. HTTP error code 500: Internal Server Error". Going to the controller's URL directly gets the same server error (which it should), so it doesn't seem to be a syntax bug.

I'm not a CI expert (yet) so it could be something simple I've overlooked. Can anyone see anything wrong with what I've done? Thanks in advance for any help.

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Paypal extends CI_Controller {

    function __construct() {
        parent::__construct();
    }
    
    function index() {
        $listener = new IpnListener();
        $listener->use_sandbox = true;
        
        try {
            $listener->requirePostMethod();
            $verified = $listener->processIpn();
        } catch (Exception $e) {
            mail('MY_EMAIL_ADDRESS', 'IPN error', $e->getMessage());
            exit(0);
        }

        if ($verified) {
            mail('MY_EMAIL_ADDRESS', 'Verified IPN', $listener->getTextReport());
        } else {
            mail('MY_EMAIL_ADDRESS', 'Invalid IPN', $listener->getTextReport());
        }
    }
}

class IpnListener {
    // Existing class untouched
}
?>

El Forum

[eluser]arkin[/eluser]
By default when a PHP error occurs, if its fatal, it can cause a 500 error. Seems like a common case of production errors not being enabled, and if they are turned on make sure in php.ini you have Display_errors = On.

El Forum

[eluser]tagawa[/eluser]
Thanks for the quick reply.
I'm not sure that's the problem in this case as I did get regular syntax errors initially, due to a couple of typos. Those are now gone so I think the PHP itself is OK - I think it's the way I've structured it that's not, but I'm not sure why.

El Forum

[eluser]weboap[/eluser]
check your apache log, for possible error messages, post the error if any.



Code:
$verified = $listener->processIpn();

i seen where you are not sending any data if you look at the class it self, the function look like
Code:
public function processIpn($post_data=null) {
....
....


on another note converting the class to CI Style code can start like :
you add a constructor to the IpnListener class

something like
http://stackoverflow.com/questions/91419...odeigniter

then place it in the library folder
after that you can do
Code:
$config = array (
                  'use_sandbox' => true,
                  'timeout'  => 60 //example of more setting
               );

$this->load->library('IpnListener', $config);

and do :

$verified = $this->IpnListener->processIpn($post_data);

El Forum

[eluser]tagawa[/eluser]
Turns out you were both right about checking the error logs more thoroughly.

I managed to find the problem - it was that CSRF protection is enabled in my config file so the PayPal POST requests were being blocked. I used the solution here to disable CSRF protection just for the PayPal controller:
http://stackoverflow.com/questions/76283...er-7705531

Again thank you both for the help. Oh, and that multiple parameter workaround is new to me - will come in handy.