paypal接口對接注意事項


追加:新的設定畫面

 

在paypal對接過程中,會存在return_url和notify兩種

分別用pdt和ipn實現

但是對於paypal,大家請注意,真實環境和沙盒測試環境的區別

你可以到www.paypal.com注冊一個賬號,然后在developer.paypal.com下面登陸,會發現生成了一個測試的商家賬號和一個測試的買家賬號,這兩個賬號是准備着方便你進行對接調試的。

但是大家不要忘了,要想測試通過,還得在www.sandbox.paypal.com用商家測試賬號登陸(記住一定要是商家測試賬號,不是買家測試賬號),在

 

 /**
     * 通過PDT驗證付款后paypal返回的數據
     * @param type $tx 交易流水號,通過Get獲取
     * @param type $pdt_identity_token 商家唯一身份標記
     * @return 訂單明細數據
     * @throws \Exception
     */
    public function verifyReturn($tx, $pdt_identity_token) {

        if(empty($tx))
        {
            throw new \Exception("Unexpected response from PayPal or Others.");
        }
        
        $encoded_data = http_build_query(array
                (
                        'cmd' => '_notify-synch',
                        'tx' => strtoupper($tx),
                        'at' => $pdt_identity_token,
                ));  

//         $encoded_data = 'cmd=_notify-synch&tx=$tx&at=$pdt_identity_token';      
        
        if ($this->use_curl) 
        {
            $this->curlPost($encoded_data); 
        }
        else 
        {
            $this->fsockPost($encoded_data);
        }
        
        $status = strpos($this->response_status, '200');       
        
        // check responses, if first 7 letters are SUCCESS then we're good
        if($this->response_status == 200 && strpos($this->response, "SUCCESS") !== false)
        {
                // get rid of success
                $curlResponse = substr($this->response, 7);
                // decode
                $curlResponse = urldecode($curlResponse);
                // make associative array
                preg_match_all('/^([^=\r\n]++)=(.*+)/m', $curlResponse, $m, PREG_PATTERN_ORDER);
                
                $curlResponse = array_combine($m[1], $m[2]);
                // keysort to keep in order
                ksort($curlResponse);
                
                // end
                return $curlResponse;
        }
        else
        {
                throw new \Exception("Invalid response status: ".$this->response_status);
        }                
    }

九域程序胡靜 2015/12/3 12:13:28

   protected function curlPost($encoded_data) {

        if ($this->use_ssl) {
            $uri = ' https://'.$this->getPaypalHost().'/cgi-bin/webscr';
            $this->post_uri = $uri;
        } else {
            $uri = ' http://'.$this->getPaypalHost().'/cgi-bin/webscr';
            $this->post_uri = $uri;
        }
        
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $uri);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//         curl_setopt($ch, CURLOPT_CAINFO, 
//         dirname(__FILE__)."/cert/cert_key.pem");
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$this->getPaypalHost()));
        
        
//         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location);
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
        
//         curl_setopt($ch, CURLOPT_HEADER, true);
        
//         if ($this->force_tls_v1) {
//             curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
//         }

        $this->response = curl_exec($ch);
        
        $this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
        
        if ($this->response === false || $this->response_status == '0') {
            $errno = curl_errno($ch);
            $errstr = curl_error($ch);
            
            throw new \Exception("cURL error: [$errno] $errstr");
        }
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM