我正在将Intuit/Quickbooks Payments API集成到现有的电子商务网站中。由于PCI要求,我需要通过JavaScript对卡数据进行标记化处理,然后使用该令牌而不是实际的卡数据提交费用。
为什么会从支付API收到“令牌无效”的错误?
第一次尝试
我遵循了此页面上的说明,其中介绍了如何使用Inuit提供的JavaScript文件对卡片数据进行标记化处理。
<script src="https://js.appcenter.intuit.com/Content/IA/intuit.ipp.payments.sandbox-0.0.3.js"></script>
intuit.ipp.payments.tokenize(
qbAppToken, {
card: {
number: $("#tokenize_cc-number").val(),
expMonth: $("#tokenize_cc-expmonth").val(),
expYear: $("#tokenize_cc-expyear").val(),
cvc: $("#tokenize_cc-cvc").val(),
address: {
streetAddress: $("#tokenize_cc-address-street").val(),
city: $("#tokenize_cc-address-city").val(),
region: $("#tokenize_cc-address-region").val(),
country: $("#tokenize_cc-address-country").val(),
postalCode: $("#tokenize_cc-address-postalcode").val()
}
}
},
function(token, response) {
console.log(response);
if (token != null) {
console.log(token);
$cardToken.val(token);
$paymentForm[0].submit();
} else {
console.log("Error during tokenization " + response.code + "; " + response.message + "; " + response.detail + "; " + response.moreinfo);
}
});
我得到一个看起来像是卡片令牌的东西:
f9e7a378-c3f2-4343-b0a8-ee376d4ed472
我将该令牌插入到我的表单中并提交表单到我的服务器,然后服务器会使用卡片令牌通过 CURL 向 Payments API 提交一笔收费。
我提交到的终端节点为:
https://sandbox.api.intuit.com/quickbooks/v4/payments/charges
Array
(
[amount] => 6992.83
[currency] => USD
[capture] => true
[token] => f9e7a378-c3f2-4343-b0a8-ee376d4ed472
[context] => Array
(
[mobile] => false
[isEcommerce] => true
)
)
但是,我从支付 API 得到的响应却显示“令牌无效”:
{
"errors": [{
"code": "PMT-4000",
"type": "invalid_request",
"message": "token is invalid.",
"detail": "token",
"infoLink": "https://developer.intuit.com/v2/docs?redirectID=PayErrors"
}]
}
以下是完整的响应:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Wed, 05 Jun 2019 18:13:20 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 175
Connection: keep-alive
Keep-Alive: timeout=5
Strict-Transport-Security: max-age=15552000
intuit_tid: [redacted]
Set-Cookie: ADRUM_BT=R:0|clientRequestGUID:9ae895d4-44ee-4175-bb47-4e37e95162a819|btId:755|backendSnapshotType:f; Expires=Wed, 5-Jun-2019 18:13:49 GMT; Path=/
{"errors":[{"code":"PMT-4000","type":"invalid_request","message":"token is invalid.","detail":"token","infoLink":"https://developer.intuit.com/v2/docs?redirectID=PayErrors"}]}
我注意到JavaScript信用卡令牌化的说明中提到:“此部分仅适用于OAuth 1.0应用程序。”这可能是一个问题。但我没有看到如何为OAuth 2.0应用程序令牌化卡数据的提及。
解释该错误
我认为“令牌无效”错误指的是我的卡片令牌而不是我的应用程序身份验证令牌。我基于以下两点做出这个假设:When I change my app authentication token, I get a different error:
{ "code": "AuthenticationFailed", "type": "INPUT", "message": null, "detail": null, "moreInfo": null }
Intuit developer relations said that the token endpoint in Intuit's JavaScript file is "incorrect", which indicates that there's a problem with the card token I'm receiving.
联系开发人员关系
Intuit开发人员关系表示:
你遇到错误的原因是,该javascript文件没有在正确的环境下正确创建令牌。
QuickBooks Payments API有两个不同的环境。一个称为沙盒环境,另一个称为生产环境。要为沙盒环境创建令牌,您需要使用此网址:https://sandbox.api.intuit.com/quickbooks/v4/payments/tokens
但是,在该javascript中,令牌的URL是:https://transaction-api-e2e.payments.intuit.net/v2/tokens,这是不正确的。这是我们使用的内部测试环境。在e2e中创建的令牌无法在沙盒中使用。这就是为什么您会得到“令牌无效”的错误。
另一种尝试
在查看API探索器和令牌端点之后,我尝试了不使用Intuit的JavaScript库生成卡片令牌。
这使用与由开发人员关系引用的API Explorer中相同的端点,尽管不存在sandbox.api.intuit.com/v4/payments/tokens,因此我认为这是一个错别字。
POST v4/payments/tokens
FOR IE8/IE9 - POST /quickbooks/v4/payments/tokens/ie
Content type: application/json
Production Base URL: https://api.intuit.com
Sandbox Base URL: https://sandbox.api.intuit.com
jQuery.ajax({
url: "https://sandbox.api.intuit.com/quickbooks/v4/payments/tokens",
type: "POST",
contentType: 'application/json',
dataType: "json",
data: JSON.stringify(cardData)
}).done(function(msg) {
...
});
结果一样。
我似乎得到了一个卡令牌,但当我通过CURL提交付款时,仍然会收到以下信息:
{
"errors": [{
"code": "PMT-4000",
"type": "invalid_request",
"message": "token is invalid.",
"detail": "token",
"infoLink": "https://developer.intuit.com/v2/docs?redirectID=PayErrors"
}]
}
出了什么问题?
我向Intuit提交了一个未解决的工单,并在开发者社区论坛发布了一篇帖子。如果我从他们那里收到任何进一步的信息,我将更新此帖子。
{value: '...'}
的JSON对象中提取出来的吗?如果不是,那么我认为有问题。他们文档中的示例令牌看起来并不像UUID。可悲的是,在他们的文档中,该属性仅被描述为字符串。他们甚至没有指定最大长度! - ficuscr