#manic-pixie-dream-bananarchist_api

1 messages ¡ Page 1 of 1 (latest)

heady oarBOT
#

👋 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/1222712471375184025

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

tawdry meadowBOT
#

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.

calm veldt
#

Hi there, once the checkout session is complete, you should expand its payment_intent, so that you can get the payment_method through checkout_session->payment_intent->payment_method

lethal spire
#

Ah i see, I didn't realize a payment intent was created as part of the checkout

#

thank you!

calm veldt
#

It depends on the checkout session's mode. If the mode is payment, then the checkout session will create a payment_intent.

lethal spire
#

our mode is subscription

calm veldt
#

Ah I see. then you should expand subscription.latest_invoice and get the payment method from checkout_session->subscription->latest_invoice->payment_intent->payment_method

lethal spire
#

do i need to specify these parameters via the expand key

#
const checkoutSession = await stripe.checkout.sessions.retrieve(sessionId);
#

is what i'm doing right now

calm veldt
#

Put subscription.latest_invoice.payment_intent in the expand array when retrieving the checkout session https://docs.stripe.com/expand

Learn how to reduce the number of requests you make to the Stripe API by expanding objects in responses.

lethal spire
#

ah i didn't realize expand allowed nested objects

#

so that implicitly expands every object in the chain?

calm veldt
#

Yes, you can expand up to 4 levels

lethal spire
#
No overload matches this call.
  Overload 1 of 2, '(id: string, params?: SessionRetrieveParams | undefined, options?: RequestOptions | undefined): Promise<Response<Session>>', gave the following error.
    Type 'string' is not assignable to type 'string[]'.
  Overload 2 of 2, '(id: string, options?: RequestOptions | undefined): Promise<Response<Session>>', gave the following error.
    Argument of type '{ expand: string; }' is not assignable to parameter of type 'RequestOptions'.
      Object literal may only specify known properties, and 'expand' does not exist in type 'RequestOptions'
calm veldt
#

Show me your code

lethal spire
#

expand is defined as a parameter though

      interface SessionRetrieveParams {
        /**
         * Specifies which fields in the response should be expanded.
         */
        expand?: Array<string>;
      }

#

oh it's an array

#

side note

#

why doesn't the typescript library type the response based on the expand key

#
      const checkoutSession = await stripe.checkout.sessions.retrieve(sessionId, {
        expand: ['subscription.latest_invoice.payment_intent'],
      });
     // (property) Stripe.Checkout.Session.subscription: string | Stripe.Subscription | null
     const sub = checkoutSession.subscription
#

since i'm expanding subscription it should know that it's not a string

lethal spire
#

@calm veldt
expansion does not work

const checkoutSession = await stripe.checkout.sessions.retrieve(sessionId, {
  expand: ['subscription.latest_invoice.payment_intent'],
});
const paymentMethod = checkoutSession.subscription.latest_invoice.payment_intent.payment_method as string;

Unable to process stripe customer hold: Cannot read properties of null (reading 'payment_method')
#

it's not expanding payment_intent

calm veldt
lethal spire
#

or rather there is no payment_intent

#

probably bc we create the subscription with a trial

#

i have the sessionId cs_test_a1XlAOVGx0RrOpfDJwSkmK70J1obf5yT3u93Xik6MghvFjiHJiHuZiNcKd

calm veldt
#

Yes you are right,

#

And actually you can get the payment_method collected by checkout from the subscription's default_payment_method

lethal spire
#

ah so it's just session.subscription.default_payment_method ?

#

only need to expand subscription

calm veldt
#

Yes

lethal spire
#

running into another problem

#

should i start a new thread

#

it's not rly related

#

@calm veldt

calm veldt
#

It's OK, we can continue here

lethal spire
#

ok great ty

#

i'm testing a flow where we accept a payment method, but create a hold on that payment method

#

my understanding was creating that hold would fail in the same way that charging a payment intent would

#

i'm testing with the stripe card id that allows creating a payment method but will fail any charges 4000000000000341

#

however my payment intent creation with capture_mode manual succeeded

calm veldt
#

What's the paymentIntent ID?

lethal spire
#

pi_3Oz96gPMRkxSx21J0VAsNGhq

calm veldt
#

You haven't confirmed the PaymentIntent.

#

It'd fail when you confirm it.

lethal spire
#

I see

#

just for me to confirm, a hold is different than a charge that is refunded correct?

#

as in if I create a hold and let it expire, i do not incurr any processing fees

calm veldt
#

Yes you are right, but you can only hold up to 7 days

lethal spire
#

perfect

#

we're creating the hold to ensure that the customer isn't starting a trial with a source that can't complete a payment

#

to navigate issues with different bank accounts selectively enforcing cvc / zip / address verification

#

and to prevent a customer from starting a trial with a card that is already maxed out