简体   繁体   中英

Stripe: Whats the different between Source vs. Card vs. Bank vs Payment Method?

I'm using Stripe for the first time an I'm little confused about the different APIs they provide. There is the Payment Method API which is the recommended one for handling payment methods for a customer but currently it supports only credit cards if I understand it correctly...

But I need different payment methods for example bank accounts. So for that Stripe provides the Card, Bank and Source object. Whats the different between them?

I tried each of them and couldn't see any difference in their behaviour. My main problem is that I want to change the default source for the payment if customer wants. So the customer object provides a default_source parameter but it doesn't change the default source when I change it. I tried to change the default from card to bank but it doesn't work. So I think I misunderstood the concept of the Payment Method, Sources, Card and Bank objects.

So can anyone explain me how I have to use these different objects?

I provide you my code below.

My code for setting default source (doesn't change anything is Stripe dashboard):

 const customer = req.body.customer; const token = req.body.token; stripe.customers.update( customer, { default_source: token //token looks like btok_231disjaohq0dj21sp } ).then(customer => { res.send(customer); }).catch(err => { res.send(err); });

Nothing changed in dashboard: 在此处输入图片说明

My code to create a bank account (this works):

 stripe.tokens.create({ bank_account: { country: 'US', currency: 'usd', account_holder_name: decoded.account_holder_name, account_holder_type: 'individual', routing_number: '110000000', account_number: '000123456789' } }).then(token => { stripe.customers.createSource( //there is .create and .createSource whats the difference? decoded.userId, { source: token.id } ).then(bank_account => { res.send(bank_account); }).catch(err => { res.send(err); }) }).catch(err => { res.send(err); });

My code to create a credit card (works):

 stripe.paymentMethods.create({ type: "card", card: { number: decoded.number, exp_month: decoded.month, exp_year: decoded.year, cvc: decoded.cvc } }).then(token => { stripe.paymentMethods.attach( token.id, { customer: decoded.customer, } ).then(card => { res.send(card); }).catch(err => { res.send(err); }); }).catch(err => { res.send(err); });

These are merely different objects/APIs Stripe has created over time. Payment Methods are the current API where new product and feature development is focused.

If you want to learn some of the history and thinking behind the progression, this blog post is an excellent resource.

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