Jason M
Jason M

Reputation: 179

How to retrieve card information such as card number with react-stripe-js?

I have

const stripeResponse = await stripe.confirmCardSetup(client_secret, {
      payment_method: {
        card: elements.getElement('cardNumber'),
        billing_details: {
          address: {
            city: selectedAddress.town,
            country: selectedAddress.country.iso3166Code,
            line1: selectedAddress.line1,
            line2: selectedAddress.line2,
            postal_code: selectedAddress.postalCode,
            state: selectedAddress.region,
          },
          email: '[email protected]',
          name,
          phone: selectedAddress.phone,
        },
      },
    });

With this I confirm card setup and I am using react-stripe-js inside react component:

import { CardNumberElement } from '@stripe/react-stripe-js';
//some component code below
...
<CardNumberElement options={options} />
...

It is not possible to get card number from CardNumberElement component.

How can I get card number with stripe?

the closest thing I could find was as below, but I need client js preferably react version of it enter image description here

Upvotes: 0

Views: 4148

Answers (2)

Sayan Dey
Sayan Dey

Reputation: 472

If you want to just get the last 4 digits of card number in React-native then

onFormComplete={cardDetails => { console.log('card details', cardDetails); setCard(cardDetails); }} 

here you will get like this in console.

card details {"brand": "Visa", "complete": true, "country": "IN", "expiryMonth": 12, "expiryYear": 2039, "last4": "4242", "postalCode": ""

OR

If you want to get all card details then

dangerouslyGetFullCardDetails={true}

Upvotes: -1

hmunoz
hmunoz

Reputation: 3341

You cannot get the card number from Stripe. That is a big part of why you need to use Stripe's libraries, so that card details don't touch your integration.

Full raw card number is never exposed in API responses from Stripe: https://stripe.com/docs/security/guide

Upvotes: 3

Related Questions