2015-03-03 30 views
0

我在我的網站上集成了PayPal。我的網站上有一個表單,它將客戶帶到PayPal完成付款,然後將其返回到我的網站。然後,我的網站使用PDT的交易標記將請求發送回PayPal,以便我可以運行一些檢查,然後使用他們購買的產品自動扣除我的客戶。PayPal集成HTTP錯誤

系統使用PHP和cURL發送這個過程。

當我使用:"www.sandbox.paypal.com/cgi-bin/webscr"

隨着沙箱憑證一切工作正常,應有盡有。

一旦我這一切改變"www.paypal.com/cgi-bin/webscr"

它不工作,我的代碼告訴我,請求失敗。 我的代碼:

$pp_hostname = "www.paypal.com"; 

     // read the post from PayPal system and add 'cmd' 
     $req = 'cmd=_notify-synch'; 

     $tx_token = $_GET['tx']; 
     $auth_token = "#######-hashed_out_here-########"; 
     $req .= "&tx=$tx_token&at=$auth_token"; 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr"); 
     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); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname")); 
     $res = curl_exec($ch); 
     curl_close($ch); 
     if(!$res){ 
       $this->twig->error("Request failed."); 
     }else{ 
      $lines = explode("\n", $res); 
      $keyarray = array(); 
      if (strcmp ($lines[0], "SUCCESS") == 0) { 
       for ($i='1'; $i<count($lines);$i++){ 
        $test = explode("=", $lines[$i]); 
        if(empty($test[1])){ 
         $keyarray[urldecode($test[0])] = ''; 
        }else{ 
         $keyarray[urldecode($test[0])] = urldecode($test[1]); 
        } 
       } 
       //give product 
      } else if (strcmp ($lines[0], "FAIL") == 0) { 
       $this->twig->error('Transaction failed!'); 
      } 
     } 

不知道爲什麼我有一個問題,所以我不知道該怎麼去修復。 我的PayPal帳戶設置爲商業,PDT和IPN打開以及自動返回

看來我收到HTTP錯誤,但我不能說,如果我記錄curl_error它只是說「」,如果我記錄curl_errno我得到0.

回答

0

我設法得到這個修復。這是由於我的服務器沒有安裝SSL證書,一旦我這樣做,它工作正常。