Welcome Guest, Not a member yet? Register   Sign In
PayPal_Lib Not Getting confirmation mail after payment.
#1

[eluser]Jenson M John[/eluser]
Hi friends,

I use Paypal Sandbox for testing payment process. Payment Works fine coz Money reduced from my paypal personal testing id & increased on my paypal business testing id. But only problem is the I'm not getting my confirmation mail for the payment & database not updating too....

I give some of payment functionality Codes here...

Creating Paypal Form
Code:
function paypal($acctype,$bus_id,$tamt,$type)
    {
            
    /*----------------------------    PAYPAL form   ---------------------------------*/
            
            
            $this->paypal_lib->add_field('business', '[email protected]');
            $this->paypal_lib->add_field('return', site_url('paypal/success'));
            $this->paypal_lib->add_field('cancel_return', site_url('paypal/cancel'));
            $this->paypal_lib->add_field('notify_url', site_url('paypal/ipn'));
            
            $this->paypal_lib->add_field('item_name', "Sample Listing");
            $this->paypal_lib->add_field('item_number', "100");
            $this->paypal_lib->add_field('amount', "500");
            
            $this->paypal_lib->add_field('userid',"10");
        // if you want an image button use this:
            $this->paypal_lib->button('Pay By Paypal');
        
        // otherwise, don't write anything or (if you want to
        // change the default button text), write this:
        // $this->paypal_lib->button('Click to Pay!');
        
              $data['paypal_form'] = $this->paypal_lib->paypal_form();
                        
    /*------------------------------------------------------------------------------*/
        $data['base'] = $this->config->item('base_url');
        $data['css'] = $this->config->item('css');
        $vals=$this->category();
        $data['count']=$vals['count'];
        $data['left_category']=$vals['left_category'];
        
            $this->load->view('paypal',$data);
        
    }

& my Paypal.php file

Code:
class Paypal extends Controller {

    function Paypal()
    {
        parent::Controller();
        $this->load->library('Paypal_Lib');
    }
    
    function index()
    {
        $this->form();
    }
    
    
    function cancel()
    {
        $data['base'] = $this->config->item('base_url');
        $data['css'] = $this->config->item('css');
        $this->load->view('payment_cancel',$data);
    }
    
    function success()
    {
        
        //$data['pp_info'] = $this->input->post();
        $data['pp_info'] = $_POST;
        $this->view('paypal/success', $data);
    }
    
    function ipn()
    {
     $to    = "[email protected]";    //  your email

        if ($this->paypal_lib->validate_ipn())
        {
            extract($_POST);
            $body  = 'An instant payment notification was successfully received from ';
            $body .= $this->paypal_lib->ipn_data['payer_email'] . ' on '.date('m/d/Y') . ' at ' . date('g:i A') . "\n\n";
            $body .= " Details:\n";
            
            foreach ($this->paypal_lib->ipn_data as $key=>$value)
            {
              $body .= "\n$key: $value";
            }

$status=$this->paypal_lib->ipn_data['payment_status'];        
        
if($status='Completed')
{
$array2 = array('name'=>$name,'bus_id'=>$bus_id,'bus_name'=>$this->paypal_lib->ipn_data['item_name'],'address'=>$address,'city'=>$city,'state'=>$state,'zip'=>$zip,'phone'=>$phone,'invoiceid'=>$invoiceid,'cc'=>$cc,'signature'=>$signature,'type'=>'PayPal','amount'=>$this->paypal_lib->ipn_data['mc_gross'],'dates'=>date("F j, Y, g:i a"));
$this->db->set($array2);
$ins2=$this->db->insert('tbl_payment');
}
    
$to1 = "[email protected]";
$subject = "Payment Confirmed";
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "Return-Path: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = "<html><body>";
$message .= "<div><img >config->item('base_url')."images/logos.jpg' width=200></div>";
$message .= "<h2>Payment Status: <font color='#FF0000'>$status</font></h2>";
$message .= "<h3>Administrator Will be reviewed your listings soon.</h3>";
$message .= "<h2>Thank You,<br><br>sample.com</h2>";
$message .= "&lt;/body&gt;&lt;/html>";
mail($to1,$subject,$message,$headers);

            
            // load email lib and email results
            $this->load->library('email');
            $this->email->to($to);
            $this->email->from($this->paypal_lib->ipn_data['payer_email'], $this->paypal_lib->ipn_data['payer_name']);
            $this->email->subject('Payment Status');
            $this->email->message($body);    
            $this->email->send();
            echo $this->email->print_debugger();
        }
        
        
    }
}

Plz help me Why i'm not getting my mail & not updating db Sad
#2

[eluser]Twisted1919[/eluser]
This is my controller
Code:
&lt;?php
class Paypal extends MY_Controller {

public function Paypal()
    {
        parent::__construct();
        $this->load->library('paypal_lib');
    }
    
function index()
    {
        header('location:'.site_url());
        die();
    }

public function payfor()
    {
        $payfor = $this->uri->segment(3);
        $ptr    = $this->uri->segment(4,0);
        $options = array(1,2,3,4,5);
        if(!is_numeric($payfor) || !in_array($payfor,$options))
            {
                header('location:'.site_url());
                die();
            }
        if($payfor == 1 )
            {
                if(strlen($ptr) < 3 ){
                header('location:'.site_url());
                die();    
                }
            }
        $user_id = 0;
        $username='';
        $for=$ptr ;    
        
        if($payfor > 1 && $this->session->userdata('logged_in') == TRUE){
        $user_id =  $this->session->userdata('member_id');
        $username= $this->session->userdata('member_username');
        $for= $ptr ;    
        }    
        $this->paypal_lib->add_field('business', '[email protected]');
        $this->paypal_lib->add_field('return', site_url());
        $this->paypal_lib->add_field('cancel_return', site_url());
        $this->paypal_lib->add_field('notify_url', site_url('paypal/ipn'));
        $this->paypal_lib->add_field('custom', $user_id.'|'.$username.'|'.$for);
        $this->paypal_lib->add_field('merchant_return_link', 'BACK');
        $this->paypal_lib->add_field('item_name', 'AAAAAAAA');
        $this->paypal_lib->add_field('item_number', $payfor);
        $this->paypal_lib->add_field('amount', '4');
        
        $this->paypal_lib->paypal_auto_form();    
    }    

function ipn()
    {
        if ($this->paypal_lib->validate_ipn())
        {
        
        $option         = $this->paypal_lib->ipn_data['item_number'];
        $data         = $this->paypal_lib->ipn_data['custom'] ;
        $in        = explode('|',$data);
        $id_user    = $in[0];
        $nume_user    = $in[1];
        $vot_ptr     = $in[2];
        $val         = strtotime("+1 month");
        
        switch($option)
            {
                //update database .....    
            }
            $body  = 'RESULT : ';
            $body .= ' Date '.date('m/d/Y') . ' hour' . date('g:i A') . "\n\n";
            $body .= " <br /><br />DT:\n<br /><br />";
            
            $al = $this->paypal_lib->ipn_data ;
            if(!empty($al) && is_array($al)){
                foreach ($al as $key=>$value){
                $body .= "\n$key: $value<br />";
                }
            }
            
            // load email lib and email results
            $config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'smtp.aaaa.aa',
                'smtp_port' => 25,
                'smtp_user' => 'aaaaa' ,
                'smtp_pass' => 'aaaaa' ,
                'useragent' => 'bbbbbbb ',
                'validate'  => TRUE ,
                'priority'  => 1 , //1-high,3-medium,5-normal
                'mailtype'  => 'html' ,
                'crlf'        => "\r\n" ,
                'newline'   => "\r\n"
                );
            $this->load->library('email',$config);
            $this->email->from('aaaaa', 'aaaaa INFO');
            $this->email->reply_to('aaaaa', 'aaaaa');
            $this->email->to('[email protected]');
            $this->email->subject('  Paypal ');
            $this->email->message($body);    
            $this->email->send();
        }else{
            header('location:'.site_url());
            die();
        }
    }
//
//    
}
?&gt;
I had to change the name from Paypal_Lib.php to Paypal_lib.php , but it works , i receive emails , and the database is updated as it should .
I'll post the lib too , with the changes i did Smile
#3

[eluser]Twisted1919[/eluser]
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');


// ------------------------------------------------------------------------

class Paypal_Lib {

    var $last_error;            
    var $ipn_log;

    var $ipn_log_file
    var $ipn_response;    
    var $ipn_data = array();
    var $fields = array();

    var $submit_btn = '';
    var $button_path = '';
    
    var $CI;
    
    function Paypal_Lib()
    {
        $this->CI =& get_instance();
        $this->CI->load->helper('url');
        $this->CI->load->helper('form');
        $this->CI->load->config('paypallib_config');
        
        $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
        //$this->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';//ptr teste
        $this->last_error = '';
        $this->ipn_response = '';

        $this->ipn_log_file = $this->CI->config->item('paypal_lib_ipn_log_file');
        $this->ipn_log = $this->CI->config->item('paypal_lib_ipn_log');
        
        $this->button_path = $this->CI->config->item('paypal_lib_button_path');
        
        $this->add_field('rm','2');              // Return method = POST
        $this->add_field('cmd','_xclick');

        $this->add_field('currency_code', $this->CI->config->item('paypal_lib_currency_code'));
        $this->add_field('quantity', '1');
        $this->button('Pay Now!');
    }

    function button($value)
    {
        // changes the default caption of the submit button
        $this->submit_btn = form_submit('pp_submit', $value);
    }

    function image($file)
    {
        $this->submit_btn = '&lt;input type="image" name="add" src="' . site_url($this-&gt;button_path .'/'. $file) . '" border="0" />';
    }


    function add_field($field, $value)
    {
        $this->fields[$field] = $value;
    }

    function paypal_auto_form()
    {

        echo '&lt;html&gt;' . "\n";
        echo '&lt;head&gt;&lt;title>Processing...&lt;/title&gt;&lt;/head>' . "\n";
        echo '&lt;body&gt;' . "\n";
        echo '<center>';
        echo '<table style="margin-top:200px;"><tr>';
        echo '<td><img src="'.base_url().'images/loading14.gif" /></td>';
        echo '<tr><td>'.$this->button('Click here...').'</td></tr>';
        echo '</tr></table>';
        echo  $this->paypal_form('paypal_auto_form');
        echo '</center>&lt;/body&gt;&lt;/html>';
    }

    function paypal_form($form_name='paypal_form')
    {
        $str = '';
        $str .= '&lt;form method="post" action="'.$this-&gt;paypal_url.'" name="'.$form_name.'"/>' . "\n";
        foreach ($this->fields as $name => $value)
            $str .= form_hidden($name, $value) . "\n";
        $str .= '<p>'. $this->submit_btn . '</p>';
        $str .= form_close() . "\n";

        return $str;
    }
    
    function validate_ipn()
    {
        $url_parsed = parse_url($this->paypal_url);          
        $post_string = '';    
        if ($_POST)
        {
            foreach ($_POST as $field=>$value)
            {
                $value = str_replace("\n", "\r\n", $value);
                $this->ipn_data[$field] = $value;
                $post_string .= $field.'='.urlencode(stripslashes($value)).'&';
            }
        }
        
        $post_string.="cmd=_notify-validate"; // append ipn command

        $fp = fsockopen('ssl://www.paypal.com',443,$err_num,$err_str,30);
        if(!$fp)
        {
            $this->last_error = "fsockopen error no. $errnum: $errstr";
            $this->log_ipn_results(false);        
            return false;
        }
        else
        {
            fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
            fputs($fp, "Host: $url_parsed[host]\r\n");
            fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
            fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $post_string . "\r\n\r\n");
            while(!feof($fp))
                $this->ipn_response .= fgets($fp, 1024);

            fclose($fp); // close connection
        }

        if (eregi("VERIFIED",$this->ipn_response))
        {
            $this->log_ipn_results(true);
            return true;        
        }
        else
        {
            $this->last_error = 'IPN Validation Failed.';
            $this->log_ipn_results(false);    
            return false;
        }
    }

    function log_ipn_results($success)
    {
        if (!$this->ipn_log) return;  // is logging turned off?

        $text = '['.date('m/d/Y g:i A').'] - ';

        if ($success) $text .= "SUCCESS!\n";
        else $text .= 'FAIL: '.$this->last_error."\n";

        $text .= "IPN POST Vars from Paypal:\n";
        foreach ($this->ipn_data as $key=>$value)
            $text .= "$key=$value, ";

        $text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response;

        $fp=fopen($this->ipn_log_file,'a');
        fwrite($fp, $text . "\n\n");

        fclose($fp);  // close file
    }


    function dump()
    {
        ksort($this->fields);
        echo '<h2>ppal->dump() Output:</h2>' . "\n";
        echo '<code style="font: 12px Monaco, \'Courier New\', Verdana, Sans-serif;  background: #f9f9f9; border: 1px solid #D0D0D0; color: #002166; display: block; margin: 14px 0; padding: 12px 10px;">' . "\n";
        foreach ($this->fields as $key => $value) echo '<strong>'. $key .'</strong>:    '. urldecode($value) .'<br/>';
        echo "</code>\n";
    }

}

?&gt;
Hope it helps , i had it working with no problems with these changes .
#4

[eluser]Jenson M John[/eluser]
Thnaks..Its Working nw Smile
#5

[eluser]MianUsman[/eluser]
Hi All,

i am having same problem for paypal using codeigniter and now i m here to get some solution i have seen your updated lib file for paypal but i m little confuse for below lines can you please explain a bit more,



$this->ipn_log_file = $this->CI->config->item('paypal_lib_ipn_log_file');
$this->ipn_log = $this->CI->config->item('paypal_lib_ipn_log');
$this->button_path = $this->CI->config->item('paypal_lib_button_path');

what will be in above stated variables in confirg file?


Thanks In Advance
Usman Abdul Razzaq
#6

[eluser]MianUsman[/eluser]
Hi All,

also i have made a config file for paypal and i gave following values to these variables
please check where i m getting wrong.



Code:
$config['paypal_lib_ipn_log_file'] = BASEPATH . 'logs/paypal_ipn.log';
$config['paypal_lib_ipn_log'] = TRUE;


at last my notify URL is not working . so i couldn't process my order on site

Please advise

Waiting for Reply

Thanks in Advance
Usman Abdul Razzaq




Theme © iAndrew 2016 - Forum software by © MyBB