Ad

Stripe: How To Create A Customer Object Given Credit Card Information

- 1 answer

Suppose the customer give the credit card information, then I can create a onetime charge object with:

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

tok allow me a one time charge. Next I would like to create a customer token for later charges, the API is

  const customer = await stripe.customers.create({
    source: 'tok_mastercard',
    email: '[email protected]',
  });

However, it's not clear what I should put into source, assuming tok is of form

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
}

Is source then tok.id or tok.card.id, or is the information even in the tok at all?

Ad

Answer

Base on the https://stripe.com/docs/api/customers/create.

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

So source is tok.id in your case.

Ad
source: stackoverflow.com
Ad