2016-04-19 32 views
6

Paypal web sitesinden örnek kod temelinde oluşturduğum bir PHP sınıfı kullanıyorum. Bunu CodeIgniter ile de kullanıyorum. IPN dinleyicisini IPN simülatörü ile test ediyorum. E-postalarım gönderildi, bu yüzden erişildiğini biliyorum. Sorun şu ki, her zaman bir INVALID cevabı alıyorum ve neden olduğu hakkında hiçbir fikrim yok. Bu, PayPal'ı sitelerimden birinde ilk defa kullanıyorum. Bu soruna ne sebep olabilir?Paypal ipn doğrulamalarım neden her zaman INVALID değerini döndürüyor?

function paypalipn(){ 

     $this->load->model('subscription'); 
     $this->load->library('paypal', array('sandbox' => true));; 

     $this->paypal->run(); 

     $fields = $this->paypal->post_fields; 

     if($this->paypal->verified){ 

      $data = array(
       'user_id' => $fields['buyer_id'], 
       'txn_id' => $fields['txn_id'], 
       'payment_gross' => $fields['mc_gross'], 
       'currency_code' => $fields['mc_currency'], 
       'payer_email' => $fields['payer_email'], 
       'plan_id' => $fields['item_number'], 
       'payment_status' => $fields['payment_status'] 
      ); 

      $this->subscription->create_payment($data); 

     } 

     $this->load->library('email'); 

     $this->email->to('*******@gmail.com'); 
     $this->email->from('**************'); 
     $this->email->subject('PayPal IPN'); 
     $this->email->message($this->paypal->result."\nAmount: ".$fields['mc_gross']."\nCurrency: ".$fields['mc_currency']."\nUser ID: ".$fields['buyer_id']); 

     $this->email->send(); 

    } 

alanların tümü $ this- e-posta iletisinde boştur ve> PayPal-> sonucu her zaman döner: Burada

<?php 

class Paypal { 

    public $sandbox = false; 
    private $_url; 
    public $verified = false; 
    public $fields = array(); 
    public $post_fields = array(); 
    public $result; 

    public function __construct($params = array()){ 

     $this->sandbox = (isset($params['sandbox'])) ? $params['sandbox'] : false; 

     $this->_url = ($this->sandbox) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; 

    } 

    public function run(){ 

     $this->verified = false; 

     // STEP 1: read POST data 
     // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. 
     // Instead, read raw POST data from the input stream. 
     $raw_post_data = file_get_contents('php://input'); 
     $raw_post_array = explode('&', $raw_post_data); 

     foreach ($raw_post_array as $keyval) { 

      $keyval = explode ('=', $keyval); 

      if (count($keyval) == 2) 

      $this->post_fields[$keyval[0]] = urldecode($keyval[1]); 

     } 

     // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' 
     $req = 'cmd=_notify-validate'; 

     if (function_exists('get_magic_quotes_gpc')) { 

      $get_magic_quotes_exists = true; 

     } 

     foreach ($this->post_fields 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"; 

     } 

     // Step 2: POST IPN data back to PayPal to validate 
     $ch = curl_init($this->_url); 
     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')); 
     // In wamp-like environments that do not come bundled with root authority certificates, 
     // please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set 
     // the directory path of the certificate as shown below: 
     curl_setopt($ch, CURLOPT_CAINFO, FCPATH.'cacert.pem'); 
     if (!($res = curl_exec($ch))) { 
      // error_log("Got " . curl_error($ch) . " when processing IPN data"); 
      curl_close($ch); 
      die('curl did not work<br>'.FCPATH.'cacert.pem'); 
     } 
     curl_close($ch); 

     if (strcmp ($res, "VERIFIED") == 0) { 

      $this->verified = true;    

     } 

     $this->result = $res; 

    } 

benim CI Kontrolör: İşte

benim sınıftır "GEÇERSİZ". Herhangi bir fikri olan var mı? Zaman ayırdığın için teşekkürler.

function paypalipn(){ 

     $this->load->model('subscription'); 
     $this->load->library('paypal', array('sandbox' => true));; 

     $this->paypal->run(); 

     $fields = $this->paypal->post_fields; 

     if($this->paypal->verified){ 

      $data = array(
       'user_id' => $fields['buyer_id'], 
       'txn_id' => $fields['txn_id'], 
       'payment_gross' => $fields['mc_gross'], 
       'currency_code' => $fields['mc_currency'], 
       'payer_email' => $fields['payer_email'], 
       'plan_id' => $fields['item_number'], 
       'payment_status' => $fields['payment_status'] 
      ); 

      $this->subscription->create_payment($data); 
     $this->load->library('email'); 
     $this->email->to('*******@gmail.com'); 
     $this->email->from('**************'); 
     $this->email->subject('PayPal IPN'); 
     $this->email->message($this->paypal->result."\nAmount: ".$fields['mc_gross']."\nCurrency: ".$fields['mc_currency']."\nUser ID: ".$fields['buyer_id']); 
     $this->email->send(); 
     } 
    } 

VEYA durumda komut durduruldu eğer deyimi tüm e-postaları almak olmaz

if($this->paypal->verified){ 

      $data = array(
       'user_id' => $fields['buyer_id'], 
       'txn_id' => $fields['txn_id'], 
       'payment_gross' => $fields['mc_gross'], 
       'currency_code' => $fields['mc_currency'], 
       'payer_email' => $fields['payer_email'], 
       'plan_id' => $fields['item_number'], 
       'payment_status' => $fields['payment_status'] 
      ); 

      $this->subscription->create_payment($data); 
} else { 
exit("We are sad to inform you that verification FAILED. Bye!"); 
} 

başarısız oldu: CI denetleyicisi olarak

+0

Paypal sınıfınız sağlam görünüyor ve kullandığım çalışma koduyla hemen hemen aynı görünüyor. Başka bir sorun olmalı ve bakılacak ilk adres SSL. SSL aslında sitenizde çalışıyor mu ve site için kullandığınız "cacert.pem" sertifikası mı? Doğrulanmış bir https bağlantısı olmadan PayPal, her zaman INVALID değerini döndürür. – DFriend

+0

Hangi yanıtı aldığınızı görmek için Paypal'daki günlük belgelerinize bakın - isteğinizi engelleyen herhangi bir şey olup olmadığını görmek için cUrl'inizi daha ayrıntılı olarak ayıklayacağım. –

+0

Bazı hata ayıklama yaptım ve $ raw_post_data'nın her zaman boş olduğunu görüyorum.Bu soruna neden olabilir mi? Bunu nasıl düzeltebilirim? – ShoeLace1291

cevap

0

böyle kodunuzu yazdım eğer . Sorun, paypal sınıfınızda public function run() içeriyor ve bu muhtemelen başarısız olan kısım.

 if (!($res = curl_exec($ch))) { 
      curl_close($ch); 
      die('curl did not work<br>'.FCPATH.'cacert.pem'); 
     } 
     curl_close($ch); 
     if (strcmp ($res, "VERIFIED") == 0) { 
      $this->verified = true;     
     } 

deneyin strcmp()strcmp() belgelerinde bir kullanıcı comment üzerinde kullanılan ve dayanır Son 3 hatları ile ilgili olarak bu

 $res=curl_exec($ch); // define $res 
     if($res==null){ // check if $res is null 
      exit('curl did not work<br>'.FCPATH.'cacert.pem'); 
     } 
     curl_close($ch); 
     if (strcmp ($res, "VERIFIED") === 0) { 
      $this->verified = true;     
     } 

gibi yeniden yazma.

  • strcmp() başarısızlık üzerine NULL döndürür.
  • Bu, eşitlik karşılaştırması (==) kullanılırken bir eşleşmenin eşleşmesinin yan etkisine sahiptir. Bunun yerine, bir NULL geri dönüşü yakalamaması gereken aynı karşılaştırmayı (===) kullanarak eşleşmeleri test etmek isteyebilirsiniz.

yukarıda ne anlama geliyor? Küçük bir örnekte.

if(null==0) { 
echo "1"; 
} 
if(null===0) { 
echo "2"; 
} 

Yukarıdaki örnek sadece sizin durumunuzda strcmp() başarısız olursa verified doğru değil true için ayarladığınız anlamına gelir çıkış => 1.

İlgili konular