#mkp_code
1 messages Β· Page 1 of 1 (latest)
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.
- mkp_docs, 54 minutes ago, 18 messages
- mkp_docs, 1 day ago, 18 messages
- mkp_async_paymentmethods_webhooks, 2 days ago, 23 messages
- mkp_webhooks, 6 days ago, 42 messages
π Welcome to your new thread!
β²οΈ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
β±οΈ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1253275469382553622
π Have more to share? Add details, code, screenshots, videos, etc. below.
async function stripePaymentIntentToObject(paymentIntent: string | Stripe.PaymentIntent | null): Promise<Stripe.PaymentIntent | null> {
if (typeof paymentIntent === 'string') {
return await stripe.paymentIntents.retrieve(paymentIntent);
} else if (typeof paymentIntent === 'object') {
return paymentIntent;
}
return null;
}
async function stripePaymentIntentToId(paymentIntent: string | Stripe.PaymentIntent | null): Promise<string | null> {
return paymentIntent?.id ?? paymentIntent;
}
Short description of the code. Let's say I wanted the id of a payment intent, but I got an object - perhaps the other way around. I would need either the id or the object. Stripe's events declarations is either string | Stripe.PaymentIntent | null for a payment intent field. So I needed to make a helper function to coalesce say the object into an id or vise versa. Throw in handling nulls because fun.
Does the API have something to do the above functionality?
you can actually do something like paymentIntent?.id ?? paymentIntent
if you want to access the ID
hmm yes that works for the object to id
oh I didn't actually see the code you've written which is exactly the same π
OH!
So yea, I guess I would like to find a simpler way for the stripePaymentIntentToObject method
Hence my question
Like an overload of stripe.paymentIntents.retrieve() that takes in a string | Stripe.PaymentIntent | null and spits back out a Stripe.PaymentIntent | null
Simply doesn't exist on the PaymentIntentsResource.d.ts
what you've written seems fine
The Stripe typescript api code base is not ready for such an overload π€£
Yay for generic code
Thanks for your help tarzan!