#mkp_code

1 messages Β· Page 1 of 1 (latest)

low voidBOT
cursive spruceBOT
#

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.

low voidBOT
#

πŸ‘‹ 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.

proud lantern
#
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;
}
prime citrus
#

πŸ‘‹ happy to help

#

would you mind elaborating?

proud lantern
#

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?

prime citrus
#

you can actually do something like paymentIntent?.id ?? paymentIntent

#

if you want to access the ID

proud lantern
#

hmm yes that works for the object to id

prime citrus
#

oh I didn't actually see the code you've written which is exactly the same πŸ˜…

proud lantern
#

I updated it don't you worry none xD

#

You were right

#

So I fixed it

prime citrus
#

OH!

proud lantern
#

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

prime citrus
#

what you've written seems fine

proud lantern
#

The Stripe typescript api code base is not ready for such an overload 🀣

#

Yay for generic code

#

Thanks for your help tarzan!

cursive spruceBOT