#Yaziiit
1 messages · Page 1 of 1 (latest)
Hi
i work with subscription
what us the best way to create a route for updating user cards ?
im using this
await this.stripe.paymentMethods.attach(
paymentMethod,
{
customer: customerId,
}
);
service side
and
const result = await stripe.createPaymentMethod(
{
card: await elements?.getElement(CardElement),
type: 'card',
billing_details: {
name: cbName,
},
})
client side
but when i use this, the old card is still by default
@hybrid brook 👋 taking over as Discord is super busy right now, answering a few other people but I'll be right back
no problem
@hybrid brook So first we recommend using the SetupIntent API to collect card details without a payment. See https://stripe.com/docs/payments/save-and-reuse this is a way better flow, allows you to do 3D Secure if needed, etc. Don't create the PM yourself and attach it.
Separately, this flow always adds the cards, it doesn't "replace" the existing one. If you want the new card to be the "default" for invoices, you need to then call the Update Customer API and explicitly set invoice_settings[default_payment_method] to the new card id pm_123: https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method