使用PayPal API获取所有交易

时间:2015-05-13 09:41:08

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

我是PayPal API的新手,我使用ExpressCheckout进行所有付款交易。我想要的是,使用start_timeend_time获取所有收到的付款交易,以便了解此交易的状态。

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

如果沙盒中有可能,我也很困惑。如果有可能请帮助我。

我使用php语言工作了一个星期。我按照PayPal中的链接,但我仍然没有得到它。 https://developer.paypal.com/docs/api/#paging--filtering

如果你有一个很好的提示,请帮助我解决我的问题。

3 个答案:

答案 0 :(得分:3)

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

当您循环浏览这些结果时,您很可能还需要为每个结果点击GetTransactionDetails以获取所需的所有信息。同样,SDK中的该模板将使您非常简单。

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

我还建议您查看PayPal IPN。这将允许您在交易到达您的帐户时获得实时更新,这样您就可以实时自动化所有内容,而不是按特定时间间隔点击TransactionSearch API。

答案 1 :(得分:1)

 # 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]));
}
?>

答案 2 :(得分:0)

试试这个

<?
     $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);

?>