2015-03-03 53 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证书,一旦我这样做,它工作正常。