【问题标题】:Get all transactions using PayPal API使用 PayPal API 获取所有交易
【发布时间】:2015-07-24 12:27:14
【问题描述】:

我是 PayPal API 的新手,我正在使用 ExpressCheckout 进行所有支付交易。我想要的是,使用start_time 和end_time 获取所有收到的付款交易,以便我知道这些交易的状态。

这样做的目的是让我的系统不时了解所有付款的状态。

如果这在沙盒中是可能的,我也很困惑。如果可以,请帮帮我。

我正在使用 php 语言工作一周。我点击了 PayPal 中的链接,但我仍然没有得到它。 https://developer.paypal.com/docs/api/#paging--filtering

如果您有好的建议,请帮助我解决我的问题。

【问题讨论】:

标签: php api paypal payment-gateway express-checkout


【解决方案1】:

@Developer Status 的回答是一个很好的示例,但我建议使用此 PayPal PHP SDK,特别是 TransactionSearch 模板,它使您的调用非常简单。它也为您处理解析所有结果。 Here you can see a sample of the full result including parsed search results(您可能需要向下滚动一点才能看到解析后的 SEARCHRESULTS。)

当您遍历这些结果时,您很可能还需要为每个结果点击GetTransactionDetails 以获得您需要的所有信息。同样,SDK 中的模板会让您非常简单。

因此,如果您下载该 SDK,使用您自己的 API 凭据调整配置文件,然后加载该示例/模板,您可以在几分钟内完成这项工作。

我还建议您查看PayPal IPN。这将允许您在交易到达您的帐户时获得实时更新,以便您可以实时自动执行所有操作,而不是在特定时间间隔访问 TransactionSearch API。

【讨论】:

    【解决方案2】:
     # You can put start date and end date here in request for `STARTDATE` AND `ENDDATE` #
    
     <?php 
     $info = 'USER=[API_USERNAME]'
            .'&PWD=[API_PASSWORD]'
            .'&SIGNATURE=[API_SIGNATURE]'
            .'&METHOD=TransactionSearch'
            .'&TRANSACTIONCLASS=RECEIVED'
            .'&STARTDATE=2013-01-08T05:38:48Z'
            .'&ENDDATE=2013-07-14T05:38:48Z'
            .'&VERSION=94';
    
    $curl = curl_init('https://api-3t.paypal.com/nvp');
    curl_setopt($curl, CURLOPT_FAILONERROR, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    
    curl_setopt($curl, CURLOPT_POSTFIELDS,  $info);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_POST, 1);
    
    $result = curl_exec($curl);
    
    # Bust the string up into an array by the ampersand (&)
    # You could also use parse_str(), but it would most likely limit out
    $result = explode("&", $result);
    
    # Loop through the new array and further bust up each element by the equal sign (=)
    # and then create a new array with the left side of the equal sign as the key and the right side of the equal sign as the value
    foreach($result as $value){
        $value = explode("=", $value);
        $temp[$value[0]] = $value[1];
    }
    
    # At the time of writing this code, there were 11 different types of responses that were returned for each record
    # There may only be 10 records returned, but there will be 110 keys in our array which contain all the different pieces of information for each record
    # Now create a 2 dimensional array with all the information for each record together
    for($i=0; $i<count($temp)/11; $i++){
        $returned_array[$i] = array(
            "timestamp"         =    urldecode($result["L_TIMESTAMP".$i]),
            "timezone"          =    urldecode($result["L_TIMEZONE".$i]),
            "type"              =    urldecode($result["L_TYPE".$i]),
            "email"             =    urldecode($result["L_EMAIL".$i]),
            "name"              =    urldecode($result["L_NAME".$i]),
            "transaction_id"    =    urldecode($result["L_TRANSACTIONID".$i]),
            "status"            =    urldecode($result["L_STATUS".$i]),
            "amt"               =    urldecode($result["L_AMT".$i]),
            "currency_code"     =    urldecode($result["L_CURRENCYCODE".$i]),
            "fee_amount"        =    urldecode($result["L_FEEAMT".$i]),
            "net_amount"        =    urldecode($result["L_NETAMT".$i]));
    }
    ?>
    

    【讨论】:

      【解决方案3】:

      试试这个

      <?
           $info = 'USER=[API_USERNAME]'
                  .'&PWD=[API_PASSWORD]'
                  .'&SIGNATURE=[API_SIGNATURE]'
                  .'&METHOD=TransactionSearch'
                  .'&TRANSACTIONCLASS=RECEIVED'
                  .'&STARTDATE=2013-01-08T05:38:48Z'
                  .'&ENDDATE=2013-07-14T05:38:48Z'
                  .'&VERSION=94';
      
          $curl = curl_init('https://api-3t.paypal.com/nvp');
          curl_setopt($curl, CURLOPT_FAILONERROR, true);
          curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      
          curl_setopt($curl, CURLOPT_POSTFIELDS,  $info);
          curl_setopt($curl, CURLOPT_HEADER, 0);
          curl_setopt($curl, CURLOPT_POST, 1);
      
          $result = curl_exec($curl);
      
          $result = explode("&", $result);
      
          foreach($result as $value){
              $value = explode("=", $value);
              $temp[$value[0]] = $value[1];
          }
      
      
          foreach($temp as $k=>$v){
              $i++;
              preg_match('#^(.*?)([0-9]+)$#is',$k,$str);
              $num=$str[2];
              $key=preg_replace('#^[A-z]_#','',$str[1]);
              if($key!=''){
      
              $new[$num][$key]=urldecode($v); 
              }
      
          }
          print_R($new);
      
      ?>
      

      【讨论】:

        猜你喜欢
        • 2015-04-30
        • 2017-04-08
        • 2022-09-23
        • 2012-04-26
        • 2019-08-14
        • 2019-12-21
        • 2014-04-29
        • 2018-12-20
        • 1970-01-01
        相关资源
        最近更新 更多