#szy_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1227618448587227188
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- szy_customer-pmmanagement, 1 day ago, 16 messages
I'd like to add what has alrady been suggested to me by 'koopajah'. It's a good help but i need a little bit more guidance:
"So right now you have to build your own UI where you can show them their list of saved PaymentMethods using the https://docs.stripe.com/api/payment_methods/customer_list API. You can mark the default based on the Customer's invoice_settings[default_payment_method] and build some UI to change the default to a new one (where your code calls the https://docs.stripe.com/api/customers/update to change that value)
And then you can have a button like "add new payment method" that then uses the SetupIntents API with the PaymentElement client-side to collect the details based on https://docs.stripe.com/payments/save-and-reuse"
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I have a question regarding the default payment method.
How do I "mark" it default? After payment through stripe checkout the default payment is not set and my customer info for invoice_settings returns:
invoice_settings: {
custom_fields: null,
default_payment_method: null,
footer: null,
rendering_options: null
},
Hello
It is possible that the default payment method was set on the subscription instead.
Have you tried retreiving the subscription object?
Yes, this seems to work ๐
const paymentMethodforStripeCustomer =
await stripe.customers.retrievePaymentMethod(
customeId,
defaultPaymentMethodId
);
Can you leave it open for another day if i run into more issues?
Idle threads are closed automatically. However, you can open a new thread instead
okay, thanks for help
Hey @junior harbor
I looked through your code too fast earlier and missed that you're NOT retrieving a subscription but just a payment method using its ID?
That feels wrong, see following for retrieving a subscription: https://docs.stripe.com/api/subscriptions/retrieve
Hey, thanks for checking in on this
i tried this before (retrieving the subscription) but it returns this:
default_payment_method: 'pm_1P3...,
so knowing the customer's id and subscription's id i thought it would be the best way. would you suggest something else?
I mean it's fine to retrieve the payment method separately. However, the subscription will by default use the payment method that's set as default on subscription.default_payment_method
So if you're trying to update that then you'll need to update the subscription object instead
(in this case just setting customer.invoice_settings.default_payment_method won't work)
sorry, im at the stage of trying to display the default payment in the ui for the user, not updating yet.
just like: Card linked: VISA **** 4242
Ah okay okay! Just wanted to make sure I didn't create more confusion ๐ Sounds good
sorry for the false alarm
cool, appreciate it anyhow
๐
Is there a way to avoid calling stripe api twice? I feel like this could be done in one call to stripe...
// goal: retrieve payment method for stripe customer from stripe
// 1. get subscription id from supabase
const subscriptionId = subscription?.id;
// 2. get customer id from stripe by looking up subscription in stripe
const existingSubscription =
await stripe.subscriptions.retrieve(subscriptionId);
const customerId = existingSubscription.customer;
// 3. get default payment method id and retrieve payment method from stripe
const defaultPaymentMethodId = existingSubscription.default_payment_method;
const paymentMethodforStripeCustomer =
await stripe.customers.retrievePaymentMethod(
customerId,
defaultPaymentMethodId
);
console.log('paymentMethodforStripeCustomer', paymentMethodforStripeCustomer);
You can expand fields when you retrieve them. If you expand customer.invoice_settings.default_payment_method when retrieving the subscription you should be able to get all of this relevant info https://docs.stripe.com/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.