简体   繁体   English

PayPal + PHP - 获取收款(开始时间/结束时间)

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

My goal is to list up all incoming(.) PayPal payments from a certain date (eg all received payments from March 09th 2021) with PHP/curl: Reading PayPal's GetStarted section I also recognized that there was a API version change from V1 to V2: ( PayPal's V1 deprecation note )我的目标是使用 PHP/curl 从某个日期(例如,从 2021 年 3 月 9 日开始收到的所有付款)列出所有传入(。) PayPal 付款:阅读 PayPal 的 GetStarted 部分我还认识到 API 版本从 V1 更改为 V2 : ( PayPal 的 V1 弃用说明)

Trying V1: For V1 some query parameters are explained that would exactly fit my needs.尝试 V1:对于 V1,解释了一些完全符合我需要的查询参数。 For example: start_time + end_time .例如: start_time时间 + end_time ( V1-Parameters ) Following the documentation I managed to fetch some payments with V1 but they do not fit the given date. ( V1-Parameters ) 根据文档,我设法使用 V1 获取一些付款,但它们不符合给定日期。 They are from somewhen of year 2018 - although the paypal account was created many years before.它们来自 2018 年的某个时候 - 尽管 paypal 帐户是多年前创建的。 So the results seems to be somewhat random style and I guess V1 doesn't work anymore for my needs.所以结果似乎有点随机,我猜 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);

Trying V2: I also managed it to fetch PayPal payment details from a certain payment using its transaction code with V2.尝试 V2:我还管理它使用 V2 的交易代码从某个付款中获取 PayPal 付款详细信息。 But for this method I need to know the transaction code before I can list the specific payment.但是对于这种方法,我需要知道交易代码才能列出具体的付款。 But I do not know the transaction codes before I know what payments have come in.但在我知道有哪些付款进入之前,我不知道交易代码。

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

(This URL above for V2 is used because "https://api-m.paypal.com/v2/payments/payment" does not exist: Returns HTML 404.) (使用上述 V2 的 URL 是因为“https://api-m.paypal.com/v2/payments/payment”不存在:返回 Z4C4AD5FCA2E7A3F74DBB1CED00381AAZ。)

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

So anyone can suggest how I could manage that?所以任何人都可以建议我如何管理它? (Maybe I'm just on a wrong way as I did not really find any helpful answers besides very old ones relating to API V1) (也许我只是走错了路,因为除了与 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)); 
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 5.1获取start_time和end_time之间的行(两个不同的字段) - Laravel 5.1 Fetch Rows between start_time and end_time (two different fields) 如何在yii2中使用start_time和end_time获取MySql中已有的记录? - How to fetch already existing records in MySql with start_time and end_time in yii2? sql使用start_time和end_time进行复杂数据排序 - sql Complex data sorting with start_time and end_time 获取每个日期 PHP 的 start_time 和 end_time 的总小时数? - Get total hours from start_time and end_time for each date PHP? 使用 PHP 从具有 start_time 和 end_time 的多维数组中查找总小时数? - Find total hours from multi-dimensional array with start_time and end_time using PHP? 7个SQL行中的第一个开始时间和最后一个结束时间,仅显示1个SQL结果 - First start_time and last end_time from 7 SQL rows to show only 1 SQL result 我想要`start_time` 和`end_time` 计数如何得到这个? - I want to `start_time` and `end_time` count how can get this? 如果在范围内找到,如何找到 start_time 和 end_time 范围,然后检查 start_date 和 end_date - How to find the start_time and end_time range if found in the range then check start_date and end_date 我想显示当前时间不在(column)start_time和end_time(column)之间的所有人员记录 - I want to display all personnel records that the current time is not between to the (column)start_time and end_time(column) 更改Facebook“ end_time”的格式 - Change Format of Facebook “end_time”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM