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
有了这个 body :
{
"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":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a2023270a3232323232323232323264242f3e" rel="noreferrer noopener nofollow">[email protected]</a>",
"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 的文档和支持非常缺乏。
最佳答案
我认为这里的问题是您尝试使用沙箱凭据 (sandbox-sq0idp-defoUOlu...
) 对您的生产位置 FPVPFZXXXXX
进行收费。如果您使用沙箱凭据调用 ListLocations
,您应该会获得一个不同的位置,然后您可以使用该位置进行沙箱收费。
关于square - Square API 充电时出现 Not Found 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42259676/