本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

将令牌化卡数据提交到 Intuit/Quickbooks Payments API 时出错

发布于2021-08-14 18:37     阅读(741)     评论(0)     点赞(30)     收藏(2)


我正在将 Intuit/Quickbooks Payments API 集成到现有的电子商务网站中。由于 PCI 要求,我需要在卡数据到达服务器之前通过 JavaScript 对其进行标记,然后使用该令牌而不是实际卡数据提交费用。

为什么我从 Payments 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
        )

)

但是,我从 Payments 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 应用程序标记卡数据。

解释错误

我认为“令牌无效”错误是指我的卡令牌而不是我的应用程序身份验证令牌。我的这个假设基于两件事:

  1. 当我更改应用程序身份验证令牌时,出现不同的错误:

    {
      "code": "AuthenticationFailed",
      "type": "INPUT",
      "message": null,
      "detail": null,
      "moreInfo": null
    }
    
  2. Intuit 开发者关系表示 Intuit 的 JavaScript 文件中的令牌端点“不正确”,这表明我收到的卡令牌有问题。

联系开发者关系

直觉开发者关系说:

您收到该错误的原因是该 javascript 文件没有在正确的环境中正确创建令牌。

QuickBooks Payments API 有两种不同的环境。一种称为沙盒环境,另一种称为生产环境。要为沙盒环境创建令牌,您需要使用此 URL: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
内容类型:application/json
生产
基础 URL:https://api.intuit.com 沙盒基础 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 的公开票如果我从他们那里收到任何进一步的信息,我会更新这篇文章。


解决方案


If you are following instructions here for tokenizing credit card informtion using the javascript file at https://js.appcenter.intuit.com/Content/IA/intuit.ipp.payments-0.0.3.js, note the response from developer relations:

...in that javascript, the URL for token is: https://transaction-api-e2e.payments.intuit.net/v2/tokens, which is incorrect. It is an internal testing environment we used. The token created in the e2e would not work for sandbox. That is why you get the token is invalid error.

For creating a token for sandbox environment, you will need to use this URL: https://sandbox.api.intuit.com/quickbooks/v4/payments/tokens

I had success requesting a card token from that Tokens endpoint via AJAX.

In addition, when using a card token to submit a charge, be sure to send a unique RequestID in the headers.

If the service receives another request with the same RequestID, instead of performing the operation again or returning an error, the service sends the same response as it did for the original request. (What is RequestId and its usage)

That's why I was still getting an "invalid token" error even after switching to the correct endpoint.



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/132060/bf526e6180f64b46028f/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

30 0
收藏该文
已收藏

评论内容:(最多支持255个字符)