使用交易ID获取交易详细信息-贝宝

时间:2018-07-12 10:48:09

标签: php api paypal

我要执行的操作是要验证Paypal付款的交易ID。但是贝宝给我回了一个邮件:

{"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https:\/\/developer.paypal.com\/docs\/api\/payments\/#errors"}

我当前的当前代码是这样:

$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/<transaction_id>");
    curl_setopt($curl, CURLOPT_POST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer ' . '<changed this to my access token>',
        'Accept: application/json',
        'Content-Type: application/json'
    ));
$response = curl_exec($curl);
$result = json_decode($response);

1 个答案:

答案 0 :(得分:3)

您使用的Paypal API端点错误。根据您对要执行的操作的描述,应根据文档使用/ v1 / checkout / orders /,因为它会为您提供特定交易的所有详细信息。

这样做:

$curl = curl_init("https://api.sandbox.paypal.com/v1/checkout/orders/<transaction_id>");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . '<access_token>',
    'Accept: application/json',
    'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);

来源:https://developer.paypal.com/docs/api/orders/v1/

相关问题