Welcome Guest, Not a member yet? Register   Sign In
Constructor being ignored after redirect from paypal
#1

[eluser]keld[/eluser]
Hello, I'm having a weird problem here.

I have a controller called booking.php that contains a checkout() function, a payment() function, a success() function and a cancel() function to use with paypal express checkout.
The transaction starts here:
mysite.com/booking/checkout where I check for the user's data being submitted, check for errors and calculate the price of the products.
When the user clickts the paypal Pay Now button, I load this url:
mysite.com/booking/payment which handles all the paypal api stuff like token, sending the user info and price to paypal then redirects to paypal to proceed with the payments. The user then pays, using paypal account or credit card then gets redirect to:
mysite.com/booking/success.

This is where it stops working, after the redirect, the constructor of the controller doesn't get loaded at all, meaning that all my CI sessions are gone, firephp output doesn't work, email lib and paypal lib don't load.
Using basic php like $_SESSION works but CI functions don't.
I have to re-declare everything in the success function.

This is what the constructor looks like:
Code:
function __construct()
    {
            parent::__construct();
            session_start();
            $this->firephp->setEnabled(TRUE);
            $this->load->library('email');
            $this->load->library('paypal');
            $this->output->enable_profiler(TRUE);
    }

My success function:

Code:
public function success(){
   session_start();
   //require 'paypal.php';
          $this->firephp->log($this->session->userdata('amount'), 'amt: ');
   $this->firephp->log($_GET['token'], 'token: ');
   $this->firephp->log($_GET['PayerID'], 'PayerID: ');
   echo "in success: ".$this->session->userdata('amount'); //DOESNT WORK
   echo "session amount: ".$_SESSION['amount']; WORKS
   echo "currency: ".$_SESSION['currency'];
    
   if(!empty($_GET['token']) && !empty($_GET['PayerID'])){
            //Update DB with payment
                        }else{
                               echo "Error, no access to this page";
                        }


Any idea why my constructor is ignored?

Thank you.
#2

[eluser]InsiteFX[/eluser]
Did you try autoloading the Session library?
#3

[eluser]keld[/eluser]
Yes it was already autoloaded. I fixed it I was in production mode so I couldn't see errors but the paypal.php library was causing some headers already sent and other stuff because when loading the library, the constructor required parameters that I wasn't providing.
So by the way how do I load a lib without causing error due to the constructor and at the same time instanciating the class. Right now I'm doing this:
Code:
$paypalParams = array('user' => $user, 'pass' => $pass, 'signature' => $signature, 'paypal_server' => $paypal_server);
$this->load->library('paypal', $paypalParams);
$paypal = new Paypal($paypalParams);

If I only do:
Code:
$this->load->library('paypal');

I get a bunch of warnings.
This is what is in the Paypal.php:
Code:
public function __construct($user, $pass, $signature, $paypal_server = 'sandbox', $request_method = 'file_get_contents'){
//blabla
}
#4

[eluser]InsiteFX[/eluser]
Either way the parameters need to be passed through the constructor for it to work.

You could rewrite the constructor to a config array and then use this:

Code:
$this->load->library('class_name', $config, 'object name');

You would need to loop through the config array and assign all the values.





Theme © iAndrew 2016 - Forum software by © MyBB