简体   繁体   中英

How to charge with Stripe by customer id

I have flow when the user can be charged by card detail, and I`m using await stripe.createPaymentMethod for that. When payment is successful I can later get details of that user purchases with card and payment info, as well as customer id "cus__idvalue".

 const { error, paymentMethod } = await stripe.createPaymentMethod({
      type: "card",
      card: elements.getElement(CardNumberElement),
      card: elements.getElement(CardExpiryElement),
      card: elements.getElement(CardCvcElement),
    });

My question is how can I charge the same user by previously used card, without giving him the option to type his card data again. I have read Stripe docs on that case, but haven`t got a clear understanding and what methods could be helpful. Appreciate any help in advance!

The functionality of what you can do is limited by what stripe API provides, i doubt if the API allows one to pre enter card details based on previous transactions, except if you store card details on your site DB, which is a security flaw.

Some card processors can allow that though, so confirm from stripe if that is allowed, in which case you can then allow users store card details in their user account on your website, so it is only when a user logs in that the pre-stored card details can be used for transactions.

PaymentMethods are only reusable when attached to a customer. To retrieve all PaymentMethods for a given customer you can use thelistPaymentMethods endpoint with a customer id parameter, and then use the PaymentMethod ID to create a new PaymentIntent like this:

const paymentIntent = await stripe.paymentIntents.create({
  amount: 2000,
  currency: "usd",
  payment_method: “REPLACE_WITH_PAYMENT_METHOD_ID”,
  confirm: true,
});

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