Search code examples
phpcodeigniterpaypalcodeigniter-2codeigniter-3

I am using paypal payment gateway, its working but some time on success auto return showing blank screen?


I am using paypal payment gateway (currently using sandbox), its working but some time on success auto return showing blank screen?? response url is pretty good, but some times after auto return its showing blank screen.

My code:

after success auto return redirect properly:

http://domainname/client/paypal/success?amt=9.24&cc=USD&item_name=Weight%20Loss%20Diet%20Program&st=Completed&tx=9CX31984H5808205U

after success auto return redirect properly but showing website blank screen:

http://domainname/client/paypal/success?amt=9.24&cc=USD&item_name=Weight%20Loss%20Diet%20Program&st=Completed&tx=9CX31984H5808205U

everything is looking good with code & return url, then why after return sometimes website showing blank screen??

My Code Snippet to execute paypal response:

switch($action){
       case "success":               

        if(isset($_GET['tx']))
                        {
                            $tx_token = $_GET['tx'];
                            $req = 'cmd=_notify-synch'; 
                            $auth_token = PDT_IDENTITY_TOKEN;
                            $req .= "&tx=$tx_token&at=$auth_token";

                            $ch = curl_init();

                        if($sandbox==0){
                              curl_setopt($ch, CURLOPT_URL, "https://www.paypal.com/cgi-bin/webscr"); //Live
                        }else{
                              curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.paypal.com/cgi-bin/webscr"); //Sandbox
                        }      

                        curl_setopt($ch, CURLOPT_POST, 1);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
                        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
                        //set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
                        //if your server does not bundled with default verisign certificates.
                        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

                        if($sandbox==0){
                              curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: www.paypal.com")); //Live
                        }else{
                              curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: www.sandbox.paypal.com")); //Sandbox
                        }                        

                        $res = curl_exec($ch);
                        curl_close($ch);  

                        $lines = explode("\n", trim($res));
                        $keyarray = array(); 

                            if (strcmp ($lines[0], "SUCCESS") == 0)
                            {
                                   for ($i = 1; $i < count($lines); $i++)
                                   {
                                      $temp = explode("=", $lines[$i],2);
                                      $keyarray[urldecode($temp[0])] = urldecode($temp[1]);
                                   }

                                   $invoice_id = $keyarray['invoice'];
                                   $transaction_id = $keyarray['txn_id'];
                                   $payment_status = $keyarray['payment_status'];
                                   if($payment_status=='Completed')
                                   {
                                      ........
                                   }
                             }
                         }
        ....
        break;
        ....
      }

Solution

  • During PayPal operations, the variables you are using are part of PDT (Paypal data transfer), which is PayPal a/c feature which needs to be enabled. Please check your PayPal a/c PDT settings once.