【问题标题】:Stripe: Whats the different between Source vs. Card vs. Bank vs Payment Method?Stripe:来源、卡、银行、支付方式有什么区别?
【发布时间】:2019-12-07 22:59:14
【问题描述】:

我是第一次使用 Stripe,我对它们提供的不同 API 有点困惑。有 Payment Method API,它是为客户处理付款方式的推荐 API,但如果我理解正确,它目前仅支持信用卡...

但我需要不同的付款方式,例如银行账户。因此,Stripe 提供了 Card、Bank 和 Source 对象。他们之间有什么不同?

我尝试了它们中的每一个,但看不出它们的行为有什么不同。我的主要问题是,如果客户愿意,我想更改付款的默认来源。所以客户对象提供了一个 default_source 参数,但是当我更改它时它不会更改默认源。我试图将默认值从卡更改为银行,但它不起作用。所以我想我误解了 Payment Method、Sources、Card 和 Bank 对象的概念。

那么谁能解释一下我必须如何使用这些不同的对象?

我在下面为您提供我的代码。

我用于设置默认来源的代码(不会改变任何东西是 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);
});

仪表板中没有任何变化:

我创建银行账户的代码(有效):

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);
    });

我创建信用卡的代码(有效):

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);
    });

【问题讨论】:

标签: node.js stripe-payments payment-gateway


【解决方案1】:

这些只是 Stripe 随时间创建的不同对象/API。 Payment Methods 是当前的 API,主要用于新产品和功能开发。

如果您想了解一些历史和进展背后的思考,this blog post 是一个很好的资源。

【讨论】:

    猜你喜欢
    • 2021-01-10
    • 2018-09-26
    • 2011-07-09
    • 2015-01-07
    • 2018-09-15
    • 2011-03-10
    • 2020-11-23
    • 2016-05-21
    • 2021-03-07
    相关资源
    最近更新 更多