Paypal通过API取消订阅无法正常工作

时间:2019-07-07 07:29:36

标签: paypal paypal-subscriptions

我正在尝试通过api取消Paypal订阅。我遵循了这份文件。 https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel

根据本文档。

curl -v -X POST https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/cancel \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token" \
-d '{
  "reason": "Not satisfied with the service"
}'

因此,我创建了以下CURL

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-X88N77T9HN56/cancel');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"reason\":\"Not satisfied with the service\"}");
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: Bearer '.$access_token;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close($ch);

    if(empty($result))die("Error: No response.");
    else
    {
        $json = json_decode($result);
        echo "<pre>";
        print_r($json);
        echo "</pre>";
    }

它对我不起作用,出现以下错误。

stdClass Object
(
    [name] => RESOURCE_NOT_FOUND
    [message] => The specified resource does not exist.
    [debug_id] => f8c1c32066dd7
    [details] => Array
        (
            [0] => stdClass Object
                (
                    [issue] => INVALID_RESOURCE_ID
                    [description] => Requested resource ID was not found.
                )

        )

    [links] => Array
        (
            [0] => stdClass Object
                (
                    [href] => https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID
                    [rel] => information_link
                    [method] => GET
                )

        )

)

0 个答案:

没有答案