• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble converting Paypal library to CI

Hi. I really like Micah's revised Paypal IPN library here:

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.

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

class Paypal extends CI_Controller {

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

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

class IpnListener {
    // Existing class untouched

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.

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.

check your apache log, for possible error messages, post the error if any.

$verified = $listener->processIpn();

i seen where you are not sending any data if you look at the class it self, the function look like
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

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

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

and do :

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

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:

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.