简体   繁体   English

Stripe:Source vs. Card vs. Bank vs Payment Method 有什么不同?

[英]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.我是第一次使用 Stripe,对它们提供的不同 API 有点困惑。 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...有一个 Payment Method API,它是推荐用于处理客户付款方式的 API,但目前它只支持信用卡,如果我理解正确的话......

But I need different payment methods for example bank accounts.但我需要不同的付款方式,例如银行账户。 So for that Stripe provides the Card, Bank and Source object.所以对于那个 Stripe 提供了 Card、Bank 和 Source 对象。 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.所以客户对象提供了一个 default_source 参数,但是当我更改它时它不会更改默认源。 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.所以我想我误解了 Payment Method、Sources、Card 和 Bank 对象的概念。

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):我用于设置默认源的代码(不会更改任何内容是 Stripe 仪表板):

 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.这些只是 Stripe 随着时间的推移创建的不同对象/API。 Payment Methods are the current API where new product and feature development is focused.支付方式是当前关注新产品和功能开发的 API。

If you want to learn some of the history and thinking behind the progression, this blog post is an excellent resource.如果您想了解一些进展背后的历史和思想,这篇博文是一个很好的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM