简体   繁体   中英

Knowing default card from stripe

I am trying to use Stripe API to get users to add payment option. This could be Credit Card or Apple Pay.

The stripe API documentation isn't really clear on how I can retrieve cards and know which is the default card. If anyone has implemented this and has a better explanation how they went about it, I would really appreciate.

Here is how I am adding card currently from fronted (iOS swift) and using NodeJS as backend.

Token is sent from tokenization of card on the client side

async addCard(req: Request, token: string) {

        const cardx = await stripe.tokens.retrieve(token);
        return cardx
    }

Here is how I retrieve the card details.

async getCards(req: Request) {
        const customer = await this.getCardCustomer(req.user);

        const cardsx = await stripe.customers.retrieve(customer.id);
        return cardsx
    }

how do I know which card is the default card. Any help is welcomed

After you tokenize the card on the client, you pass the token back to your server and attach it to your Customer object. The simplest way to do this is via the source parameter , which will then automatically set that card as the default_source for the Customer. After that, you can retrieve the Customer and that indicates the set default_source .

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