【问题标题】:PayPal REST API shipping address CodeigniterPayPal REST API 送货地址 Codeigniter
【发布时间】:2014-02-11 12:40:26
【问题描述】:

如何使用 paypal REST api 通过TOKEN 获取送货地址?我发现this 很有用,但我在任何地方都看不到使用示例。

【问题讨论】:

    标签: paypal paypal-rest-sdk


    【解决方案1】:

    我在这个问题上苦苦挣扎,终于找到了解决方案,所以如果其他人需要,我想分享它。

    所以问题:如何通过TOKEN获取订单详情?

    添加此功能:

    function PPHttpPost($methodName_, $nvpStr_) {
          $environment = 'sandbox'; // or 'beta-sandbox' or 'live'
    
          // Set up your API credentials, PayPal end point, and API version.
          $API_UserName = urlencode('xxxxxxxxxx');
          $API_Password = urlencode('xxxxxxxxxx');
          $API_Signature = urlencode('xxxxxxxxxx');
          $API_Endpoint = "https://api-3t.paypal.com/nvp";
          if("sandbox" === $environment || "beta-sandbox" === $environment) {
            $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
          }
          $version = urlencode('85.0');
    
          // Set the curl parameters.
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
          curl_setopt($ch, CURLOPT_VERBOSE, 1);
    
          // Turn off the server and peer verification (TrustManager Concept).
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_POST, 1);
    
          // Set the API operation, version, and API signature in the request.
          $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
    
          // Set the request as a POST FIELD for curl.
          curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
    
          // Get response from the server.
          $httpResponse = curl_exec($ch);
    
          if(!$httpResponse) {
            exit('$methodName_ failed: '.curl_error($ch).'('.curl_errno($ch).')');
          }
    
          // Extract the response details.
          $httpResponseAr = explode("&", $httpResponse);
    
          $httpParsedResponseAr = array();
          foreach ($httpResponseAr as $i => $value) {
            $tmpAr = explode("=", $value);
            if(sizeof($tmpAr) > 1) {
              $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
            }
          }
    
          if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
            exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
          }
    
          return $httpParsedResponseAr;
        }
    

    只需调用该函数即可:

    // Set request-specific fields.
    $token = urlencode(htmlspecialchars($data['TOKEN'])); //$data['TOKEN'] is token
    // Add request-specific fields to the request string.
    $nvpStr = "&TOKEN=$token";
    $httpParsedResponseAr = $this->PPHttpPost('GetExpressCheckoutDetails', $nvpStr);
    print_r($httpParsedResponseAr); // will hold all details such as shipping address, country...
    

    另外,您可以添加检查支付是否成功:

    if( "SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]) ) { .. }
    

    reference

    【讨论】:

      猜你喜欢
      • 2019-04-01
      • 2014-12-06
      • 2014-06-21
      • 2021-12-19
      • 2013-10-09
      • 1970-01-01
      • 2013-10-30
      • 2021-05-22
      • 2021-04-05
      相关资源
      最近更新 更多