12
votes

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: enter image description here

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);
    });
1
The Payment Methods API is currently replacing the Tokens and Sources API due to European regulation mandating "Strong Customer Authentication" (SCA) by the 14 September 2019 deadline.Flux
Here's a link to Stripe's language re: "Legacy APIs": stripe.com/docs/payments/legacy-apisandrewhaines
Does this answer your question? Stripe Payments: Source vs Token/Card?tbhaxor

1 Answers

1
votes

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.