简体   繁体   中英

Attach Card to Customer Record

I'm currently learning the Stripe API with a test card and Test Secret Key. I'm attempting to create a test card token and then create a customer object with that card token. I plan on using that card token for future transactions.

I can successfully generate the card token using the /v1/tokens endpoint and then I can successfully create a customer using the /vi/customers endpoint. However, I can't seem to assign the token or card ID from the card token step to the customer in step 2.

I've attempted to use the sources attribute to reference the card token while creating the customer (the token ID nor the card ID seem to be working for me) and I've also attempted to run an update on the customer to attach the source card token without any issue. I've also attempted to create a new card object via /v1/customers/:id/sources but that doesn't seem to work.

Any advice on what steps I need to do to accomplish this via Stripe API only?

Using the token id, you should be able to attach this to the customer during creation with the source (singular!) parameter , for example source=tok_123 . After creation, you would instead make a separate attach call:

curl https://api.stripe.com/v1/customers/cus_345/sources \
  -u sk_test_123: \
  -d source=src_567

Instead of this, though, I'd recommend using our updated Payment Method and Setup Intents APIs to save a card for future payments following this guide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM