Stripe 再次返回相同的标记

Stripe returning same token again

我正在使用 stripe 来管理我的交易。

我需要添加客户(如果不存在)然后将卡添加到该客户。

现在我必须为我通过

完成的两个进程获取令牌
stripe.tokens.create({
    card: {
        "number": "4242424242424242",
        "exp_month": "1",
        "exp_year": "2019",
        "cvc": "123"
    }
}, function (err, token) {
    // asynchronously called
    if (token != null) {
        //Do something
    }
    else {
         //Do something
    }
});

现在我调用此方法两次,每次都获取新令牌以添加客户(如果不存在)并向该客户添加卡。但是每次我收到与发送相同卡信息的相同响应时。

    1St

{
  "id": "tok_16v4mvBR7e7FUB557PD3hOZc",
  "object": "token",
  "card": {
    "id": "card_16v4mvBR7e7FUB55KD06kqJo", 
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Diners Club",
    "country": null,
    "cvc_check": "unchecked",
    "dynamic_last4": null,
    "exp_month": 10,
    "exp_year": 2021,
    "fingerprint": "iE2uiiDxUFHRgpt1",
    "funding": "credit",
    "last4": "5904",
    "metadata": {},
    "name": null,
    "tokenization_method": null
  },
  "client_ip": "51.25.52.52",
  "created": 1444650501,
  "livemode": false,
  "type": "card",
  "used": false
}

2nd
{
  "id": "tok_16v4mvBR7e7FUB557PD3hOZc",
  "object": "token",
  "card": {
    "id": "card_16v4mvBR7e7FUB55KD06kqJo",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Diners Club",
    "country": null,
    "cvc_check": "unchecked",
    "dynamic_last4": null,
    "exp_month": 10,
    "exp_year": 2021,
    "fingerprint": "iE2uiiDxUFHRgpt1",
    "funding": "credit",
    "last4": "5904",
    "metadata": {},
    "name": null,
    "tokenization_method": null
  },
  "client_ip": "55.55.55.55",
  "created": 1444650501,
  "livemode": false,
  "type": "card",
  "used": false
}

检查每个字段是否与第一个相同。

但是如果我想使用我第一次得到的相同令牌,我会收到错误

Stripe Error 400 - Cannot use stripe token more than once

所以我的问题是,如果我再次获得相同的令牌,那么为什么在使用第一次返回的令牌添加客户并为该客户添加卡时出现错误。

如果我不必再次获取令牌,这可能会提高我的站点速度。

来自@Matthew Arkin 的评论

I have a need to add the customer (if not already present) and then add the card to that customer.

stipe 的业务逻辑是这样的,当您要求用户提供信用卡详细信息时,它才会添加客户,因此他们没有不同,但程序相同。

条带令牌是一种编码以下内容的方法:

1) 一个银行账户

2) 信用卡详细信息

要获得令牌,您应该传递信用卡的卡信息,例如 here

现在您可以使用 stripe.js 获得相同的令牌。使用 stripejs 的好处是将发送令牌而不是卡信息。

要添加客户,您应该提供来自 stripe.js(或来自 api)的令牌或卡信息。使用令牌是我认为最好的方法。

当您使用令牌调用条带时,您会自动创建带有卡的客户。因此,如果没有提供给 stripe 的卡信息,则无法创建客户

如果您想为现有客户添加卡,请执行以下操作:

**1) 检索客户传递的客户 ID **

2) 检查客户是否为空,然后为从 stripe.js

获取令牌的客户添加卡