#ctodan
1 messages · Page 1 of 1 (latest)
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
You're using the ios payment sheet, right?
yes correct
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
im more thinking about when the subscription renews
i want to first try the payment method that was initially used
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
It will depend on your integration, but the first invoice payment for a subscription would be what I'd use
Wait sorry, can you clarify what API i use to do this?
the invoice is automatically created when creating the subscription no?
To set it? Customer update
https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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?
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?
a little bit of both
The old sources is necessary for bank account, because we use plaid to verify the bank account
Our new payment method integration for US bank accounts offers the verification another way, btu that's your choice
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
In this case when creating a source then you can set the customer default_source afterward
when do i set it tho
I dont create the credit card source
it gets created automatically with the payment sheet
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
Flow is as follows:
- User subscription is created
- User chooses to pay with bank account (legacy plaid source) or Payment element (using credit card)
- User goes through whatever flow they want
- 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.
Correct, you need to set that. You can have the subscription set the subscription default after payment success, but not the customer invoice default
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
Yep so you can add:
payment_settings.save_default_payment_method=on_subscription
https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
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
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:
- explicit payment method for invoice payment, if provided
default_payment_methodon the subscription, if set- customer
invoice_settings[default_payment_method], if set and suitable for the invoice to be paid - customer
default_sourceif set and suitable for the invoice to be paid
https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority
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?
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.
gotcha
is that something that happens automatically?
or is it something I need to code?
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