无法使用PayPal REST API(v2)获取交易详细信息

时间:2019-08-24 11:18:35

标签: php curl paypal paypal-rest-sdk php-curl

我想使用PayPal REST API通过ID来获取PayPal交易的全部详细信息。

我尝试按照以下步骤进行操作:

<?php
include("config.php");

// Reference: https://developer.paypal.com/docs/api/get-an-access-token-curl/
$ch = curl_init("https://api.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Accept: application/json",
    "Accept-Language: en_US"
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_USERPWD, $restapp['client_id'] . ':' . $restapp['secret']);
$result = curl_exec($ch);
curl_close($ch);
$access_token = json_decode($result, true)['access_token'];

// Reference: https://developer.paypal.com/docs/checkout/reference/server-integration/get-transaction/#on-the-server
$ch = curl_init("https://api.paypal.com/v2/checkout/orders/<transaction_id>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json",
    "Accept: application/json",
    "Authorization: Bearer " . $access_token
));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

但这总是返回错误INVALID_RESOURCE_ID。请注意,我正在使用我的实时应用程序的客户端ID和客户端密钥,并且我使用的事务ID也是实时事务ID。

进行了一些搜索之后,我发现https://api.paypal.com/v1/payments/orders/<transaction_id>可以代替https://api.paypal.com/v2/checkout/orders/<transaction_id> ..但是v1的返回信息不如v2

我在v2终结点上做错了什么?

亲切的问候。

0 个答案:

没有答案