结算计划补丁:HTTP 400 - 提供的无效路径

时间:2016-07-28 16:37:44

标签: paypal paypal-sandbox

我正在尝试删除所有CREATED商业计划:

for (Plan plan : created.getPlans()) {

    List<Patch> patchRequestList = new ArrayList<>();

    Map<String, String> value = new HashMap<>();
    value.put("state", "DELETED");

    Patch patch = new Patch();
    patch.setPath("/v1/payments/billing-plans/" + plan.getId());
    patch.setValue(value);
    patch.setOp("replace");

    patchRequestList.add(patch);

    plan.update(apiContext, patchRequestList);
}

但我得到的只是:

Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.sandbox.paypal.com/v1/payments/billing-plans/P-8SX60559PJ5455037EICJEYY
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1889)

根据documentation,我认为我做得对。但是,我试过了

patch.setPath("/v1/payments/billing-plans/" + plan.getId());
patch.setPath("/v1/payments/billing-plans");
patch.setPath("/payments/billing-plans);

等。但这些都不起作用。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

嗯,我有点困惑。 documentation

{
  "path": "/",
  "value": {
    "state": "ACTIVE"
  },
  "op": "replace"
}

他们真的意味着:

Patch patch = new Patch();
patch.setPath("/");
patch.setValue(value);
patch.setOp("replace");

当然有道理。为什么要设置自

以来的路径
plan.update(apiContext, patchRequestList);

已经为你做到了。我想patch.setPath()就是设置一个额外的相对路径。

现在你知道了。