首页 > 解决方案 > 有什么方法可以代表客户添加跟踪信息?

问题描述

有没有办法使用新的 REST API 代表其他客户添加跟踪信息字段?如果没有,我还能创建使用旧 API 或任何其他方式的贝宝应用程序吗?

有一个老问题展示了我正在尝试做的事情。

通过遵循此文档页面,我设法使用以下 C# 代码更新了我的沙盒帐户的信息...

private static string SendRequest()
{
    var client = new HttpClient();
    var end_point = "https://api.sandbox.paypal.com/v1/shipping/trackers-batch";
    try
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
        var requestMessage = new HttpRequestMessage
        {
            RequestUri = new Uri(end_point),
            Method = HttpMethod.Post,

        };
        string clientId = "";
        string secret = "";

        requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic",
            Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes($"{clientId}:{secret}")));

        string body = File.ReadAllText("data.json");
        requestMessage.Content = new StringContent(body, Encoding.UTF8, "application/json");
        var x = client.SendAsync(requestMessage).Result;
        string responseStr = x.Content.ReadAsStringAsync().Result;

        return responseStr;
    }
    catch (Exception exp)
    {
        Debug.Print(exp.Message);
        return null;
    }
    finally
    {
        client.Dispose();
    }
}

数据.json

{
  "trackers": [
    {
      "transaction_id": "04YE27.....",
      "tracking_number": "443844....",
      "status": "SHIPPED",
      "carrier": "FEDEX"
    }
  ]
}

但是,即使我将该帐户设置中的权限授予我的应用程序,它也无法更新另一个沙盒帐户数据。这是服务器响应:

{
   "tracker_identifiers":[

   ],
   "errors":[
      {
         "name":"NOT_AUTHORIZED",
         "message":"Authorization failed due to insufficient permissions",
         "details":[
            {
               "field":"/trackers/1/transaction_id",
               "value":"04YE27.....",
               "location":"body",
               "issue":"USER_NOT_AUTHORIZED",
               "description":"You are not authorized to add or modify tracking number for this transaction"
            }
         ],
         "links":[

         ]
      }
   ],
   "links":[
      {
         "href":"https://api.sandbox.paypal.com/v1/shipping/trackers-batch",
         "rel":"self",
         "method":"POST",
         "encType":"application/json"
      }
   ]
}

我可以要求用户授予我的应用所需的权限。但我不能要求每个人都创建一个应用程序并给我他们的客户 ID 和密码。

标签: paypalpaypal-sandboxpaypal-rest-sdk

解决方案


我不能要求每个人都创建一个应用程序并给我他们的客户 ID 和密码。

这正是您需要做的,以便对其 PayPal 帐户中的交易级别信息进行这种级别的精细控制。

除了为您创建应用程序并共享其凭据之外,他们没有授予权限的机制。

如果没有,我还能创建使用旧 API 或任何其他方式的贝宝应用程序吗?

旧的 API 和应用程序不提供更新跟踪信息的方法。新集成也不支持它们,并且不应再使用它们(仅限向后兼容性/维护)


推荐阅读