【问题标题】:Is there any way to add tracking info on behalf of the clients?有什么方法可以代表客户添加跟踪信息?
【发布时间】:2020-01-22 13:43:15
【问题描述】:

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

有一个旧的Question 展示了我正在尝试做的事情。

通过关注Documentation page,我设法使用以下 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 和密码。

【问题讨论】:

    标签: paypal paypal-sandbox paypal-rest-sdk


    【解决方案1】:

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

    这正是您需要对他们的 PayPal 帐户中的交易级别信息进行这种级别的细粒度控制。

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

    如果不能,我还能创建使用旧 API 或任何其他方式的 paypal 应用吗?

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

    【讨论】:

    • 谢谢@Preston,看来这是唯一的出路。我已经可以访问他们帐户的二级用户,作为替代解决方案,如果他们添加了“API 激活和授权”权限,我可以代表他们创建应用程序吗?我只是希望找到一种方法让这听起来不那么尴尬。
    • 我认为你需要这个和其他的东西,比如查看个人资料/登录权限。但听起来你已经有了这些。
    猜你喜欢
    • 2011-07-01
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 1970-01-01
    • 2015-09-08
    • 2013-09-23
    • 2021-09-17
    相关资源
    最近更新 更多