【问题标题】:PayPal + PHP - Fetch incoming payments (start_time / end_time)PayPal + PHP - 获取收款(start_time / end_time)
【发布时间】:2021-06-07 08:39:39
【问题描述】:

我的目标是使用 PHP/curl 列出某个日期(例如,从 2021 年 3 月 9 日起收到的所有付款)的所有传入(!)PayPal 付款。阅读 PayPal 的 GetStarted 部分,我还发现 API 版本从 V1 更改为 V2:(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”不存在:返回 HTML 404。)

$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 相关的非常古老的答案之外,我并没有真正找到任何有用的答案)

【问题讨论】:

    标签: php curl paypal payment


    【解决方案1】:
        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)); 
        }
    

    【讨论】:

      猜你喜欢
      • 2020-11-17
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 2011-01-08
      • 2013-08-29
      相关资源
      最近更新 更多