cancel
Showing results for 
Search instead for 
Did you mean: 

IPN problem

Options
pippuccio76
Contributor
Posted on

HI , this is my listener :

 $this->paypal_lib->log_ipn_test("Entrato in IPN");

        if (!count($_POST)) {
            throw new Exception("Missing POST Data");
            $this->paypal_lib->log_ipn_test('Non arrivano i dati via post ');
        }
        $raw_post_data = file_get_contents('php://input');
        $raw_post_array = explode('&', $raw_post_data);
        $myPost = [];
        foreach ($raw_post_array as $keyval) {
            $keyval = explode('=', $keyval);
            if (count($keyval) == 2) {
                if ($keyval[0] === 'payment_date') {
                    if (substr_count($keyval[1], '+') === 1) {
                        $keyval[1] = str_replace('+', '%2B', $keyval[1]);
                    }
                }
                $myPost[$keyval[0]] = urldecode($keyval[1]);
            }

            $this->paypal_lib->log_ipn_test(' Dati arrivati ');

        }
        $req = 'cmd=_notify-validate';
        $get_magic_quotes_exists = false;
        if (function_exists('get_magic_quotes_gpc')) {
            $get_magic_quotes_exists = true;

            $this->paypal_lib->log_ipn_test('Magic quote true !! ');

        }
        foreach ($myPost as $key => $value) {
            if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
                $value = urlencode(stripslashes($value));
            } else {
                $value = urlencode($value);
            }
            $req .= "&$key=$value";

            $this->paypal_lib->log_ipn_test('Chiave => Valore ');

        }
        $ch = curl_init(info('link_paypal', 'shop'));
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        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);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
        $res = curl_exec($ch);
        $info = curl_getinfo($ch);
        $http_code = $info['http_code'];
        if ($http_code != 200) {
            throw new Exception("PayPal responded with http code $http_code");

            $this->paypal_lib->log_ipn_test("PayPal responded with http code $http_code");

        }
        if (!($res)) {
            $errno = curl_errno($ch);
            $errstr = curl_error($ch);
            curl_close($ch);
            throw new Exception("cURL error: [$errno] $errstr");

            $this->paypal_lib->log_ipn_test("cURL error: [$errno] $errstr");

        }

        $this->paypal_lib->log_ipn_test("RES: $res");
        curl_close($ch);

        
        $paypalInfo = $this->input->post();

        $data['azienda_id']     = $paypalInfo['custom'];
        $data['preventivo_id']  = $paypalInfo["item_number"];
        $data['txn_id']         = $paypalInfo["txn_id"];
        $data['payment_gross']  = $paypalInfo["mc_gross"];
        $data['currency_code']  = $paypalInfo["mc_currency"];
        $data['payer_email']    = $paypalInfo["payer_email"];
        $data['payment_status'] = $paypalInfo["payment_status"];


        if ($res == 'VERIFIED') {
            // Paypal return transaction details array

            $this->paypal_lib->insertTransaction($data);

            //TODO
            //cambiare lo stato del preventivo 

            //TODO
            //cambiare lo stato del lavoro

            //TODO
            //eliminare pulsanti paypal e bonifico
            
            //TODO
            //Abilitare azienda a visualizzazione cliente

            //TODO
            //Mandare mail a cliente

            //TODO
            //Mandare mail a azienda




            return true;

        } else {
            return false;
        }
    } 

i use codeigniter , and in my account i set the listener url :

 

paypal.png

but dont work , why ?

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.