#maufcost - SS Payment Intent confirmation

1 messages ยท Page 1 of 1 (latest)

shell cipher
#

HI again ๐Ÿ‘‹

twin dragon
#

Awesome. Thanks. Another quick question: I'm trying to get the client secret from a subscription schedule I am creating with:

const schedule = await stripe.subscriptionSchedules.create({
        customer: customerId,
        start_date: 'now',
        end_behavior: 'cancel',
        phases: [
            {
                items: [{
                    price: price.id,
                    quantity: 1,
                }],
                iterations: numberOfIterations,
            },
        ],
        // Allows us to simultaneously create a payment
        // intent and get its client secret.
        expand: ['subscription.latest_invoice.payment_intent']
    })

However, the .paymentIntent property is always null when I try to access: schedule.subscription.latest_invoice.payment_intent.client_secret.

shell cipher
#

Can you share the ID of the subscription schedule?

twin dragon
#

Yes: sub_1LKQHJDTqg4XgBDsV493w2U9

shell cipher
#

The payment Intent for that invoice (in_1LKQHJDTqg4XgBDsksEXdEqh) is null. ๐Ÿค”

twin dragon
#

Correct

#

Is there another property I should be passing perhaps when creating the subscription schedule?

shell cipher
#

Checking on that

#

Oh, got it!

#

The invoice is in draft mode

#

It'll stay that way for 1 hour to allow an last minute changes

#

The Payment Intent gets generated once the Invoice is finalized

twin dragon
#

It does that inherently? Isn't there a way for me to get the client secret immediately so that I can charge the customer at the time the user is on the checkout page?

shell cipher
#

In this case it has to do with the fact you created the sub through a schedule. You can speed the process along by finalizing the Invoice through the API.

twin dragon
#

So, I can create the subscription schedule with the call I currently have and then create another call to finalize an invoice instantaneously?

shell cipher
#

Yeah so you would just retrieve the subscription.latest_invoice ID value and use that in the Finalize API call

twin dragon
#

Got it! And after finalizing the invoice, how can I retrieve its PI?

shell cipher
#

You would pass the expand parameter on the Finalize API call. expand=['payment_intent'] and retrieve the client_secret

twin dragon
#

Sweet! Thanks a lot again ๐Ÿ™‚