#paris-paymentelement-attachment
1 messages · Page 1 of 1 (latest)
there is a paymentId in the subscription latest invoice
i am actually migrating from card element
to payment element
sure but the Payment Element is just confirming the PaymentIntent
so that shouldn't change anything
with card element i was creating a payment method with the card element. i was passing that to server side and was attaching that to the customer
yes that's why I'm asking for a clear example like pi_123 or sub_123
and also adding it as default payment
pi_3KZJQmFvraRjEeWm01rlnObl
on test environment
that one worked right and has a card attached?
exactly
and also has a payment method
pm_1KZNoiFvraRjEeWmDSUuJvny
but when i try to call the update method it complains with this message This customer has no attached payment source or default payment method..
what update method? I don't see an error
ah I see it on the sub. Have you made sure the payment method was attached? This is done async after the confirmation
so maybe you called the Subscription update too early?
not it was after 😄
maybe 1 - 2 minutesw after
so after i have my subscription i then try to update it to see if everything works
so from server side i call const subscription = await stripe.subscriptions.update(subscriptionID, {
items: [{ id: priceID, quantity: quantity}],
proration_behavior: 'always_invoice',
payment_behavior: 'pending_if_incomplete',
});
but that's different
that's trying to change a subscription. Did you set a default payment method on the subscription or the customer?
with card element i used to create a paymentmethod, attach it to customer and make that default payment before i create the subscription
If not we don't know what card to use. It's attached, sure, but it's not the default. What if you had more than one
the same thing happened with the card element
but with payment elements, i have to create the subscription before i have a payment method
so i can get a client secret
So in that case you need to catch the successful payment and then explicitly mark that PaymentMethod as the default for future invoices
so i will try to get the succesfull payment ident from the subscription so i can get the payment method, and then will do somthing like
await stripe.paymentMethods.attach(paymentMethodID, {
customer: customerID,
});
// Set the payment method as the 'default' for this customer
await stripe.customers.update(customerID, {
invoice_settings: {
default_payment_method: paymentMethodID,
},
});
did i get that right?