首页 > 解决方案 > Paypal 沙箱 INVALID_RESOURCE_ID RESOURCE_NOT_FOUND

问题描述

在沙盒版本上运行时出现资源未找到错误,但在实时运行时可以找到。有人可以告诉我如何解决这个错误吗?

这是我的代码

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n  \"plan_id\": \"P-97A61885CU957844JMFV\",\n  \"start_time\": \"2021-10-19T00:00:00Z\",\n   \"shipping_amount\": {\n    \"currency_code\": \"USD\",\n   \"custom_id\": \"xxxxdxxx\",\n   \"value\": \"10.00\"\n  },\n  \"subscriber\": {\n    \"name\": {\n      \"given_name\": \"John\",\n      \"surname\": \"Doe\"\n    },\n    \"email_address\": \"customer@example.com\",\n    \"shipping_address\": {\n      \"name\": {\n        \"full_name\": \"John Doe\"\n      },\n      \"address\": {\n        \"address_line_1\": \"2211 N First Street\",\n        \"address_line_2\": \"Building 17\",\n        \"admin_area_2\": \"San Jose\",\n        \"admin_area_1\": \"CA\",\n        \"postal_code\": \"95131\",\n        \"country_code\": \"US\"\n      }\n    }\n  },\n  \"application_context\": {\n    \"brand_name\": \"SAMPLEBRAND\",\n    \"locale\": \"en-US\",\n    \"shipping_preference\": \"SET_PROVIDED_ADDRESS\",\n    \"user_action\": \"SUBSCRIBE_NOW\",\n    \"payment_method\": {\n      \"payer_selected\": \"PAYPAL\",\n      \"payee_preferred\": \"IMMEDIATE_PAYMENT_REQUIRED\"\n    },\n    \"return_url\": \"https://sample.com/webhook_paypal.php\",\n    \"cancel_url\": \"https://sample.com/webhook_paypal.php\"\n  }\n}");

    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: Bearer '.$token;
    $headers[] = 'Paypal-Request-Id: SUBSCRIPTION-21092019-001';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

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

标签: paypal

解决方案


P-97A61885CU957844JMFV

使用适当的沙盒帐户为沙盒环境创建这样的计划 ID(和产品 ID),并改用这些沙盒 ID。您可以通过https://www.sandbox.paypal.com/billing(使用沙盒帐户的凭据登录)或 API(使用沙盒帐户的客户端 ID 和密码)进行操作


Live Plan ID 将永远无法在沙盒环境中创建订阅,也无法在实时环境中创建沙盒订阅。这两个环境是完全分开的。

在 developer.paypal.com 仪表板中管理您的沙盒帐户沙盒应用程序。


推荐阅读