Visualizzazione risultati 1 fino 5 di 5

Discussione: ipn paypal

  1. #1
    Guest

    Predefinito ipn paypal

    Salve , ho un problema con ipn di paypal , sia con sandbox che con ipn simulator non ricevo risposta , cioè il pagamento è ok , ho il redirect ma l'ipn (il listener) non riceve risposta .

    Il codice è questo :

    Codice:
     $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);
    
                return true;
    
            } else {
                return false;
            }
        }


    log_ipn_test scrive semplicemente in un file log.


    Ipn simulator risponde invece così :

    IPN was not sent, and the handshake was not verified.


    Come posso risolvere ?
    Ultima modifica di preventivoamianto : 14-08-2018 alle ore 13.27.34

  2. #2
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,148

    Predefinito

    Hai abilitato le connessioni server to server?

    Ciao!

  3. #3
    Guest

    Predefinito

    Si abilitate e tolte anche le restrizioni per sicurezza.

  4. #4
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,148

    Predefinito

    Puoi provare a verificare la connessione tramite questo script? (devi caricare i due file cacert.pem e TlsCheck.php, quindi eseguire quest'ultimo).

    Ciao!

  5. #5
    Guest

    Predefinito

    Ho risolto in parte , ora paypal riesce a rispondermi ma nonostante il VERIFIED Paypal continua a inviarmi messaggi IPN con la conseguenza che inserisco troppi record nel db e una serie di conseguenze...

    Codice:
    public function ipn()
        {
    
    
    
            if ( ! $this->input->post()) {
                
    
                throw new Exception("Missing POST Data");
            }
    
    
    
            $raw_post_data = file_get_contents('php://input');
            $raw_post_array = explode('&', $raw_post_data);
            $myPost = array();
            foreach ($raw_post_array as $keyval) {
                $keyval = explode('=', $keyval);
                if (count($keyval) == 2) {
                    // Since we do not want the plus in the datetime string to be encoded to a space, we manually encode it.
                    if ($keyval[0] === 'payment_date') {
                        if (substr_count($keyval[1], '+') === 1) {
                            $keyval[1] = str_replace('+', '%2B', $keyval[1]);
                        }
                    }
                    $myPost[$keyval[0]] = urldecode($keyval[1]);
                }
            }
            // Build the body of the verification post request, adding the _notify-validate command.
            $req = 'cmd=_notify-validate';
            $get_magic_quotes_exists = false;
            if (function_exists('get_magic_quotes_gpc')) {
                $get_magic_quotes_exists = 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($req);
            
            // Post the data back to PayPal, using curl. Throw exceptions if errors occur.
            $ch = curl_init($this->ipn_paypal_url);
            
            $this->paypal_lib->log_ipn_test('CH:'.$ch);
            
            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_SSLVERSION, 6);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            // This is often required if the server is missing a global cert bundle, or is using an outdated one.
            if ($this->use_local_certs) {
                curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cert/cacert.pem");
            }
            curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'User-Agent: PHP-IPN-Verification-Script',
                'Connection: Close',
            ));
    
            $res = curl_exec($ch);
            $this->paypal_lib->log_ipn_test('RES:'.$res);
    
            if ( ! ($res)) {
                $errno = curl_errno($ch);
                $errstr = curl_error($ch);
                curl_close($ch);
    
                $this->paypal_lib->log_ipn_test("cURL error: [$errno] $errstr");
    
                throw new Exception("cURL error: [$errno] $errstr");
            }
    
            $info = curl_getinfo($ch);
    
            $this->paypal_lib->log_ipn_test("INFO: ".print_r($info));
    
            $http_code = $info['http_code'];
    
            $this->paypal_lib->log_ipn_test("http_code: ".$http_code);
    
            if ($http_code != 200) {
    
                $this->paypal_lib->log_ipn_test("PayPal responded with http code $http_code");
                throw new Exception("PayPal responded with http code $http_code");
            }
            
    
    
            // Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
            header("HTTP/1.1 200 OK");
    
    
            
            // inspect IPN validation result and act accordingly
            if (strcmp ($res, "VERIFIED") == 0) {
    
    
                    // The IPN is verified, process it
    
    
                    foreach($this->input->post() as $key => $value) {
                           
                        $this->paypal_lib->log_ipn_test( $key . " = " . $value );
                    }
    
    
                    
                    // Paypal return transaction details array
                    $paypalInfo = $this->input->post();
    
                    $azienda_id     = $paypalInfo['custom'];
                    $preventivo_id  = $paypalInfo["item_number"];
                    $txn_id         = $paypalInfo["txn_id"];
                    $payment_gross  = $paypalInfo["mc_gross"];
                    $currency_code  = $paypalInfo["mc_currency"];
                    $payer_email    = $paypalInfo["payer_email"];
                    $payment_status = $paypalInfo["payment_status"];
    
    
    
    
    
                    $this->paypal_lib->log_ipn_test("RES VERIFIED");
    
    
                    // Insert the transaction data into the database
                    if($this->preventivi_paypal_model->insertTransaction(
    
    
                        $azienda_id,
                        $preventivo_id,
                        $txn_id,
                        $payment_gross,
                        $currency_code,
                        $payer_email,
                        $payment_status
    
    
                    ) ){
    
                        $this->paypal_lib->log_ipn_test('Inserita transazione nel db ');
    
    
    
                        $this->paypal_lib->log_ipn_test('pagamento verificato');
                        $this->paypal_lib->log_ipn_test('azienda_id:'.$paypalInfo['custom']);
                        $this->paypal_lib->log_ipn_test('preventivo_id:'.$paypalInfo['item_number']);
                        $this->paypal_lib->log_ipn_test('txn_id:'.$paypalInfo['txn_id']);
                        $this->paypal_lib->log_ipn_test('mc_gross:'.$paypalInfo['mc_gross']);
                        $this->paypal_lib->log_ipn_test('mc_currency:'.$paypalInfo['mc_currency']);
                        $this->paypal_lib->log_ipn_test('payer_email:'.$paypalInfo['payer_email']);
                        $this->paypal_lib->log_ipn_test('payment_status:'.$paypalInfo['payment_status']);
    
    
                        #############################################
                        //Invio mail a cliente
                        #############################################
    
                        //recupero id del lavoro dal preventivo
                        $preventivo=$this->preventivi_inviati_aziende_model
                                         ->get_Preventivi_inviati_aziende($paypalInfo['item_number']);
    
                        //recupero id del cliente dal lavoro
                        $lavoro=$this->lavori_model->get_Lavori($preventivo->id_lavori);
    
    
                        //recupero i dati del cliente 
                        $cliente=$this->clienti_model->get_Clienti($lavoro->id_clienti);
    
                        //invio mail a cliente
    
                        if($this->send_mail_cliente_preventivo_pagato_paypal($cliente->email) ){
    
                            $this->paypal_lib->log_ipn_test('mail inviata al cliente : '.$cliente->email);
    
                        }
    
                        
    
                        #############################################
                        //Cambio lo stato del preventivo
                        #############################################
    
                        if($this->preventivi_inviati_aziende_model->set_stato($preventivo->id,4)){
    
                            $this->paypal_lib->log_ipn_test('Cambio stato preventivo (4) : '.$preventivo->id);
    
                        
                        }
    
    
                        #############################################
                        //cambiare lo stato del lavoro
                        #############################################
    
                        if($this->lavori_model->set_stato($preventivo->id_lavori,4)){
    
    
                            $this->paypal_lib->log_ipn_test('Stato lavoro modificato : '.$preventivo->id_lavori);
                        
                        }
    
    
                        #############################################
                        //cambio il tipo di pagamento nel preventivo
                        #############################################
    
    
                         if($this->preventivi_inviati_aziende_model->set_metodo_pagamento($preventivo->id,2)){
    
                            $this->paypal_lib->log_ipn_test('Cambio stato metodo pagamento (2) : '.$preventivo->id);
    
                        
                        }
    
    
    
    
                        #############################################
                        //Invio mail a admin
                        #############################################
    
                        if($this->send_mail_admin_preventivo_pagato_paypal($paypalInfo["item_number"]) ) {
    
                            $this->paypal_lib->log_ipn_test('Mail inviata a admin : '.$preventivo->id_lavori);
    
    
                        }
    
    
    
    
    
                        ############################################
                        // INSERisci transazione in preventivo
                        #############################################
    
                          if($this->preventivi_inviati_aziende_model->inserisci_transazione_paypal($txn_id)){
    
                            $this->paypal_lib->log_ipn_test('Transazione inserita in preventivi');
    
                        
                        }
    
    
    
    
            
               }    
                
            } else {
    
    
                $this->paypal_lib->log_ipn_test('NOT VALID '.$res);
                return false;
            }
    
    
    
        }

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •