对Square沙箱的GuzzleHttp POST请求返回“无法授权此请求”,尽管凭证具有正确的(?)信息

问题描述 投票:0回答:1

某些背景:

我正在尝试使用Drupal的webform模块使用我帐户的沙箱设置中的凭据向https://connect.squareup.com/v2/payments发出REST API请求。该模块通过instantiating a new Client object然后调用方法post(string $request_url, array $request_options)来使用GuzzleHttp。 $request_options数组包括一个'headers'数组和一个'json'数组(后者的键被替换为'body')。

我在做什么:

我正在尝试从Square的“付款API”文档的'Create payment'部分重新创建示例请求。我已经根据需要修改了一些内容,包括:

  • 已替换 ACCESS_TOKEN和我的“沙箱访问令牌”
  • 已替换 source_id,带有测试卡随机数“ cnon:card-nonce-ok”]
  • << [已删除 customer_id,因为我没有引用客户
  • 已替换
  • location_id,带有“默认测试帐户”的位置ID
最终的cURL看起来像:

curl https://connect.squareup.com/v2/payments \ -X POST \ -H 'Square-Version: 2020-04-22' \ -H 'Authorization: Bearer {{ SANDBOX_ACCESS_TOKEN }}' \ -H 'Content-Type: application/json' \ -d '{ "idempotency_key": "4935a656-a929-4792-b97c-8848be85c27c", "amount_money": { "amount": 200, "currency": "USD" }, "source_id": "cnon:card-nonce-ok", "autocomplete": true, "location_id": "{{ DEFAULT_TEST_ACCOUNT_LOCATION_ID }}", "reference_id": "123456", "note": "Brief description", "app_fee_money": { "amount": 10, "currency": "USD" } }'

但是我在调​​试时只得到以下响应:

401 Response status code: Date: - 'Mon, 27 Apr 2020 23:58:54 GMT' Frame-Options: - DENY X-Frame-Options: - DENY X-Content-Type-Options: - nosniff X-Xss-Protection: - '1; mode=block' Content-Type: - application/json Content-Length: - '124' Strict-Transport-Security: - 'max-age=631152000; includeSubDomains; preload' Response header: {"errors": [{"code": "UNAUTHORIZED","detail": "This request could not be authorized.","category": "AUTHENTICATION_ERROR"}]} Response body: errors: - code: UNAUTHORIZED detail: 'This request could not be authorized.' category: AUTHENTICATION_ERROR

我被困的地方:

我已经在本地使用本地证书进行了尝试,现在已经投入生产(仍然具有沙盒凭据)。我怀疑可能是问题出在打印headers的关联数组包含'Authorization' => "Bearer ACCESS_TOKEN",该数组在值周围产生了单引号。但是我对此不太确定。还有其他方法可以调试Square根据请求得到的内容吗?还有其他任何想法或问题吗?
rest sandbox guzzle square drupal-webform
1个回答
0
投票
沙盒环境域-connect.squareupsandbox.com,而您的curl请求是connect.squareup.com,用于生产调用。
© www.soinside.com 2019 - 2024. All rights reserved.