#khris-subscription-setupintent

1 messages ยท Page 1 of 1 (latest)

slender bayBOT
patent cobalt
#

Hi ๐Ÿ‘‹ can you share the ID of a Subscription from your testing where you saw this behavior?

median bay
#

I can try... it's currently just in test code, and I'm stepping through it line by line in my server-side code

#

sub_1NLpanBRcLdcM5pSv3JqeGyx

#

I havent got to the line where it tries to access the PendingSetupIntent and hence its clientsecret

#

it appears to have a PendingSetupIntentId of

seti_1NLpaoBRcLdcM5pShkzlNs2Q

#

but the object itself is null

patent cobalt
#

Hm, from my end it looks like a pending setup intent was created when the Subscription was created.

#

What do you mean the object is null? How are you trying to access the client secret?

median bay
#

like this:

#

subscription.PendingSetupIntent.ClientSecret

patent cobalt
#

What request is providing the subscription that you're referencing?

What I think is happening is you aren't expanding the pending_setup_intent field so it is providing a string with the ID of a Setup Intent instead of a nested object, so when you try to drill in to get the client secret you are trying to access fields that don't exist and get a null value instead.

median bay
#

not sure what you mean by expanding the pending_setup_intent field

patent cobalt
#

Can you show me the code that you're using to populate your subscription variable?

median bay
#

sure one sec

#

it's in VB I'm afraid

#

Dim subsService As New SubscriptionService()
Dim subsOptions As New SubscriptionCreateOptions()
subsOptions.Customer = cust.Id
subsOptions.PaymentBehavior = "default_incomplete"

    subsOptions.TrialEnd = DateTimeOffset.FromUnixTimeSeconds(unixTime).UtcDateTime
    subsOptions.ProrationBehavior = "none"

    subsOptions.PaymentSettings = paymentSettings
    subsOptions.Items = New List(Of SubscriptionItemOptions)

    Dim subItem As New SubscriptionItemOptions()
    subItem.Price = Price.Id

    subsOptions.Items.Add(subItem)

    Dim subscription As Subscription = subsService.Create(subsOptions)
patent cobalt
#

Thank you! Yeah, I think what I described is what is happening.

By default the pending_setup_intent field on a Subscription only provides you with the ID of the Setup Intent. In order to instead have the Setup Intent object returned in line with the Subscription object you will need to use our expand feature:
https://stripe.com/docs/api/expanding_objects?lang=dotnet

You will want to expand pending_setup_intent when making the request to create the Subscription, then I believe you'll be able to reference the client secret as you're trying.

The sample code provided in this section includes that use of expand, and can be used as a reference:
https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#create-subscription

slender bayBOT
median bay
#

Ok thank you, I'll give that a go. Appreciate your time.

patent cobalt
#

Any time, happy to help!

median bay
#

So options.AddExpand("subscription")?

valid shoal
#

khris-subscription-setupintent

#

no that would expand a subscription property on a Subscription object which doesn't make sense

median bay
#

apols.

valid shoal
#

you set the name of what you want to expand, in this case you want to turn the pending_setup_intent: 'seti_123' in the full SetupIntent object

median bay
#

options.AddExpand("pending_setup_intent") or something like that?

valid shoal
#

so you want our API to return pending_setup_intent: { id:'seti_123', object: 'setup_intent', ...., client_secret: 'xxxx', .... } does that make sense?

#

yep try that it should work!

median bay
#

ok thanks

valid shoal
#

@median bay did it work?

median bay
#

Seems to, yes. The AddExpand results in the property not being null, and it has a clientsecret

#

Just trying to sort out mounting the payments element now

valid shoal
#

yay

median bay
#

specifically the options parameter

#

the client secret has the customer product and price all baked in, presumably, so I don't need to explicitly set amount?

valid shoal
#

correct

median bay
#

Ok, well thanks for you help. My brain is fried now, so I'm giving up for today.

valid shoal
#

One day at a time ๐Ÿ™‚

median bay
#

Correct ๐Ÿ™‚

#

Thanks again.