重复预防
在制作API请求时,即使您的请求实际完成成功完成,也可以接收错误。
例如,如果您提交API请求并超时,则可以确定是否通过Chargify或不收到您的请求。
如果您只需重新尝试请求,请您 可能 最终有重复的交易。
唯一性令牌
In order to prevent these duplicates, Chargify allows you to supply a uniqueness_token
parameter in any POST
or PUT
request.
The value you supply for the uniqueness_token
should be long and random, like a UUID. The exact format of the value is up to you.
If a subsequent request with the same uniqueness_token is received within 60 minutes, it will be rejected with a 409 Conflict
response code and a duplicate error message.
例子
For example, suppose you are making an adjustment on a subscription. Using curl, you send the following POST request, including a uniqueness_token
.
curl --verbose -u $CHARGIFY_API_KEY:x -H Accept:application/json -H Content-Type:application/json -X POST \
-d @adjustment.json //$CHARGIFY_SUBDOMAIN.ikvrej.icu/subscriptions/$SUBSCRIPTION_ID/adjustments.json
adjustment.json:
{"adjustment":
{
"amount": "-12.43",
"memo": "Credit for outage on 1/31"
},
"uniqueness_token": "2731FB23-98AD-4489-BAF6-7D5CE916F766"
}
After you send your request, there is some problem, and the request times out without a valid response instead of the 201 Created
you were hoping for.
Since you have supplied a uniqueness_token
, you can safely re-try the request.
If you receive the expected 201 Created
(or 422 Unprocessable Entity
) response, you can continue as usual knowing that Chargify never received your first request.
If you receive a 409 Conflict
and a duplicate error message for the re-try, then you know that the first request was received and responded to.
示例409冲突响应:
< Status: 409 Conflict
{"errors":["复制Prevention::DuplicateSubmissionError"]}
不幸的是,不可能知道第一个请求的结果是什么,因此您无法自动假设它成功。
根据您所做的任何类型的请求,可以通过录制有关原始请求的一些信息,侦听Webhook的一些信息来优雅地恢复,并匹配Webhook有效载荷以了解请求是否成功。
在其他情况下,需要人为干预。
概括
我们希望此功能有助于您在错误处理期间防止重复事务。
那说,如果你经历了重复超时,请 开票 所以我们可以调查。