Search code examples
stripe-paymentsreact-stripe

How to get stripe card number, cvc and expiry date from the react stripe PaymentElement


I have a question for you. How can I access the card details, like the last number of cards, expiry date, and CVC from the PaymentElement? I am using the @stripe/react-stripe-js package here. Here are the checkout form code:

 <form ref={connectRef} id="payment-form" onSubmit={handleSubmit}>
  <PaymentElement
    id="payment-element"
    options={{
      layout: 'accordion',
    }}   
  />  
</form>

Can we get the card details from here?


Solution

  • Payment method information collected using PaymentElement gets tokenized by Stripe for security and safety reasons.

    When the information gets tokenized, it creates a PaymentMethod object. You can retrieve the PaymentMethod object using the API and look at the card parameter to get last 4 and expiry.

    I don't believe Stripe API returns cvc as that could have security implications.