#ctodan

1 messages · Page 1 of 1 (latest)

fallow laurelBOT
deft herald
#

To give more context this is an investing flow, so users always connect their bank account, even if they pay for the subscription with a credit card.

#

Issue im trying to handle is if user pays with card first, then connects their bank account, the bank account seems to be set as the default payment method. If the user pays with card, it doest automatically get set as the default payment method

uncut kayak
#

You're using the ios payment sheet, right?

deft herald
#

yes correct

uncut kayak
#

Gotcha - then unfortunately I think you're a bit stuck. The ios payment sheet will default to displaying the most recently created payment method when it's opened

fallow laurelBOT
deft herald
#

im more thinking about when the subscription renews

#

i want to first try the payment method that was initially used

uncut kayak
#

Then you should be setting invoice_settings.default_payment_method on the Customer as soon as the payment is used for the first time

#

and that should use it for all future subscription payments

deft herald
#

where is the best place to do that?

#

in a webhook?

candid sundial
#

It will depend on your integration, but the first invoice payment for a subscription would be what I'd use

deft herald
#

Wait sorry, can you clarify what API i use to do this?

#

the invoice is automatically created when creating the subscription no?

candid sundial
#

To set it? Customer update

deft herald
#

And when should i call this though?

#

For bank account it makes sense (and actually set it to default automatically)?

#

const stripeBankAccountToken = await plaidService.createStripeBankAccountToken(user)
const stripeCustomer = await this.createOrGetCustomer(user._id.toString())

        const bankAccount = await this.stripe.customers.createSource(stripeCustomer.id, {
            source: stripeBankAccountToken.stripe_bank_account_token,
        })
#

but for the ios payment sheet im not sure

#

would i do it in some webhook?

candid sundial
#

Well that's the old Sources integration pattern, which is different than using payment methods

#

Are you building this new, or making changes to an existing integration?

deft herald
#

a little bit of both

#

The old sources is necessary for bank account, because we use plaid to verify the bank account

candid sundial
#

Our new payment method integration for US bank accounts offers the verification another way, btu that's your choice

deft herald
#

its not teneble for us. Plaid is integrated with another partner for the user to fund thier investment accounts

#

So we def dont want to make the user connect thier bank account twice

#

But i think thats beside the point here. I really just want to make sure to set the default payment method once the user pays

candid sundial
#

In this case when creating a source then you can set the customer default_source afterward

deft herald
#

when do i set it tho

#

I dont create the credit card source

#

it gets created automatically with the payment sheet

candid sundial
#

I'm confused about the flow here -- you were talking about bank account sources using plaid & sources api

#

Now you're referring to cards created via the mobile payment element?

#

In both cases, you can look at the payment method used for the first invoice payment on a subscription

deft herald
#

Flow is as follows:

  1. User subscription is created
  2. User chooses to pay with bank account (legacy plaid source) or Payment element (using credit card)
  3. User goes through whatever flow they want
  4. Later in flow, user has to link bank anyways (to use our investment product and fund their account). When this happens, the default payment method automatically gets set to the bank_account
#

My goal is in step 3, to set the default payment method to whatever the user chose to pay for the subscription with

#

If they use the bank account its easy enough, becuase it seems to happen automaticially when calling createSource

#

If the user uses a credit card via the mobile payment element, the card they use is not automatically set as the default payment.

candid sundial
#

Correct, you need to set that. You can have the subscription set the subscription default after payment success, but not the customer invoice default

deft herald
#

i see, how do i do that?

#

await this.stripe.subscriptions.create({
customer: stripeCustomerId,
items: [{ price: subscriptionPlan.stripePriceID }],
payment_behavior: "default_incomplete",
payment_settings: {
payment_method_types: ["us_bank_account", "card"],
},
collection_method: "charge_automatically",
expand: ["latest_invoice.payment_intent"],
})

#

this is how i create the subscription

candid sundial
#

Yep so you can add:

deft herald
#

Gotcha. Does this field take precedence over the customer default payment method?

#

it seems that when createSource is called, it automatically sets the bank to the default payment method on the customer

candid sundial
#

Whoops missed this update here

#

Yes, that behaviour happened automatically in the old sources API

#

But does not with payment methods

#

No, the priority is:

Learn how to specify which payment methods are allowed for a subscription.

fallow laurelBOT
deft herald
#

ok got it, cool, i think this solves my issue

#

related question. Lets say user pays with card year 1 and that fails in year 2. Is there a way to charge the bank account on file when the failure happens?

dusky kelp
#

Hello, catching up with this thread, will be able to answer your latest questions in a minute

#

Yes, retrying with another saved payment method is definitely a valid option though you may want to make sure your users know that you will fall back like that.

deft herald
#

gotcha

#

is that something that happens automatically?

#

or is it something I need to code?

dusky kelp
#

You will need to code it as far as I know. I think our automatic retries will only retry on the payment method or source that is set as the default