为Square API充电时找不到错误

时间:2017-02-15 20:44:56

标签: square square-connect

Square REST API文档声明我应该获取我的位置列表,然后在我调用事务端点时使用返回的位置代码(以便对信用卡收费)。我正在这样做,但返回的错误表明商家没有提供ID的位置。

我在发送到事务端点的JSON中使用和不使用location_id尝试了这个,因为它是路径变量。结果相同。我还在Square的API FAQ中看到,找不到404的常见原因是卡片随机数被创建错误,但是这个回复明确说明位置ID无效。

我已经使用Postman和JSON对此进行了测试,我可以看到位置代码是正确的。以下是我的电话和回复:

这是一个GET请求:

https://connect.squareup.com/v2/locations

以下是回复:

{
"locations": [
{
  "id": "FPVPFZ4DXXXXX",
  "name": "MyCompany",
  "address": {
    "address_line_1": "123 Candy Lane",
    "address_line_2": "",
    "locality": "Smithfield",
    "administrative_district_level_1": "RI",
    "postal_code": "02917",
    "country": "US"
  },
  "timezone": "America/Los_Angeles",
  "capabilities": [
    "CREDIT_CARD_PROCESSING"
  ]
},
{
  "id": "4FHNAN1WXXXXX",
  "name": "MyCompany2",
  "address": {
    "address_line_1": "567 Smith Street",
    "address_line_2": "",
    "locality": "Greenville",
    "administrative_district_level_1": "RI",
    "postal_code": "02828-2910",
    "country": "US"
  },
  "timezone": "America/Los_Angeles",
  "capabilities": [
    "CREDIT_CARD_PROCESSING"
  ]
 }
 ]
 }

我在上面的示例中稍微修改了返回的ID。

接下来,我打电话给这张uri充电:

https://connect.squareup.com/v2/locations/FPVPFZ4DXXXXX/transactions

有了这个机构:

{  
"note":"",
"idempotency_key":"azsxdcfvrtrewsdf",
"location_id":"FPVPFZ4DXXXXX",
"shipping_address":{  
  "address_line_1":"123 My Street",
  "address_line_2":null,
  "locality":"Greenville",
  "administrative_district_level_1":"RI",
  "postal_code":"02828",
  "country":"US"
},
"billing_address":{  
  "address_line_1":"123 My Street",
  "address_line_2":null,
  "locality":"Greenville",
  "administrative_district_level_1":"RI",
  "postal_code":"02828",
  "country":"US"
},
"card_nonce":"CBASEPPW7fjdUHe-3jP6ZZ4kvE0gAQ",
"reference_id":"RT-12345678",
"amount_money":{  
  "amount":12500,
  "currency":"USD"
},
"delay_capture":true,
"buyer_email_address":"jim@xxxxxxxxxx.net",
"customer_id":"JIM"
}

我收到了这个回复:

{
"errors": [
{
  "category": "INVALID_REQUEST_ERROR",
  "code": "NOT_FOUND",
  "detail": "This merchant does not have a location with the ID    `FPVPFZ4DXXXXX`.",
  "field": "location_id"
}
]
}

因此,位置ID与位置端点返回的ID完全匹配。

熟悉此API的人可以帮助我吗?可悲的是缺乏Square的文档和支持。

1 个答案:

答案 0 :(得分:3)

我认为此处的问题是您尝试使用沙箱凭据(sandbox-sq0idp-defoUOlu...)对生产地点FPVPFZXXXXX收取费用。如果您使用沙盒凭据调用ListLocations,则应该获得一个不同的位置,然后您可以使用沙盒收费。