paypal接口对接注意事项 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");
        }
    }
分类: php
标签: paypal
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值