PayPal + PHP - 获取收款 (start_time / end_time)

PayPal + PHP - Fetch incoming payments (start_time / end_time)

我的目标是使用 PHP/curl 列出从特定日期开始的所有收款(!)PayPal 付款(例如,从 2021 年 3 月 9 日开始收到的所有付款)。阅读 PayPal 的 GetStarted 部分,我还认识到从 V1 到 V2 有 API 版本更改:(PayPal's V1 deprecation note)

正在尝试 V1: 对于 V1,一些查询参数的解释完全符合我的需要。例如:start_time + end_time。 (V1-Parameters) 根据文档,我设法使用 V1 获取了一些付款,但它们不符合给定的日期。它们来自 2018 年的某个时候——尽管贝宝账户是多年前创建的。所以结果似乎有点随机风格,我猜 V1 不再满足我的需要。

$live_url = "https://api-m.paypal.com/v1/payments/payment";
$myStart_time = date("Y-m-d")."T00:00:00Z";                                 // e.g. 2021-03-09T00:00:00Z
$myEnd_time = date("Y-d-m", time()) ."T". date("H:m:s", time()) . "Z";      // e.g. 2021-03-09T14:21:00Z

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $live_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $client_id.":".$paypal_secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "start_time=".$myStart_time);
curl_setopt($ch, CURLOPT_POSTFIELDS, "end_time=".$myEnd_time);
curl_setopt($ch, CURLOPT_POSTFIELDS, "total_count_required=true");
curl_setopt($ch, CURLOPT_POSTFIELDS, "start_index=0");
curl_setopt($ch, CURLOPT_POSTFIELDS, "sort_by=update_time");
curl_setopt($ch, CURLOPT_POSTFIELDS, "sort_order=desc");
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Accept-Language: en_US", 'Content-Type: application/x-www-form-urlencoded'));
$result = curl_exec($ch);

尝试使用 V2: 我还设法使用 V2 的交易代码从特定付款中获取 PayPal 付款详细信息。但是对于这种方法我需要知道交易代码才能我可以列出具体的付款方式。但是我不知道交易代码,才知道有什么付款进来。

$payments_url = "https://api.paypal.com/v2/payments/captures/$transaction_code";

(上面V2的URL是因为“https://api-m.paypal.com/v2/payments/payment”不存在:Returns HTML404.)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $payments_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $client_id.":".$paypal_secret);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $access_token,
    'Accept: application/json',
    'Content-Type: application/json'
));
$result = curl_exec($ch);

所以任何人都可以建议我如何管理它? (也许我只是走错了路,因为除了与 API V1 相关的非常古老的答案外,我没有真正找到任何有用的答案)

    echo "<br>REPORT TRANSACTIONS<br>";
    $live_url = "https://api-m.paypal.com/v1/reporting/transactions";

    $transactions_url = "?start_date=2021-03-17T00:00:00Zend_date=2021-03-18T13:50:59Z&fields=all";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $live_url . $transactions_url);

    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
//  curl_setopt($ch, CURLOPT_POSTFIELDS, "start_date=".($myStart_time));
//  curl_setopt($ch, CURLOPT_POSTFIELDS, "end_date=".($myEnd_time));
    curl_setopt($ch, CURLOPT_POSTFIELDS, "fields=all");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "page_size=10");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "page=1");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "sync_mode=false");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_USERPWD, $client_id.":".$paypal_secret);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Accept: application/json", 
        "Accept-Language: en_US", 
        "Authorization: Bearer " . $access_token,
        "Content-Type: application/json"
    ));

    $result = curl_exec($ch);
    $info = curl_getinfo($ch);      
    $err = curl_error($ch);

    echo "<hr>";

    if ($err) {
      echo "<br>cURL Error: $err <br>Info: $info <br>Result: $result";
    }
    else
    {
        echo "<pre>";
        print_r($info);
        print_r($r = json_decode($result)); 
    }