代码之家  ›  专栏  ›  技术社区  ›  xiaolingxiao

Stripe:如何在给定信用卡信息的情况下创建客户对象

  •  2
  • xiaolingxiao  · 技术社区  · 5 年前

    let tok = await stripe.tokens.create({
        card: {
         number: '4242424242424242',
        exp_month: 12,
        exp_year: 2020,
        cvc: '123'
      }
    })
    

    tok 允许我一次性收费。接下来我想为以后的收费创建一个客户令牌,API是

      const customer = await stripe.customers.create({
        source: 'tok_mastercard',
        email: 'paying.user@example.com',
      });
    

    然而,我不清楚我应该投入什么 source ,假设 是形式的

    const tok = {
      "id": "tok_1DHGtNDubJ4bIrUdqXvAGo4m",
      "object": "token",
      "card": {
        "id": "card_1DHGtNDubJ4bIrUd2OyUHWNw",
        "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": "Visa",
        "country": "US",
        "cvc_check": null,
        "dynamic_last4": null,
        "exp_month": 8,
        "exp_year": 2019,
        "fingerprint": "rhpDLcuYn3stjjKR",
        "funding": "credit",
        "last4": "4242",
        "metadata": {},
        "name": "Jenny Rosen",
        "tokenization_method": null
      },
      "client_ip": null,
      "created": 1538598261,
      "livemode": false,
      "type": "card",
      "used": false
    }
    

    来源 tok.id tok.card.id 托克 完全?

    1 回复  |  直到 5 年前
        1
  •  3
  •   Tien Duong Thomas Blobaum    5 年前

    基于 https://stripe.com/docs/api/customers/create .

    Source is a Token’s or a Source’s ID, as returned by Elements
    

    所以源头是 tok.id