#juan-pablo_api

1 messages ยท Page 1 of 1 (latest)

serene oakBOT
#

๐Ÿ‘‹ 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/1278122833364516990

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

ripe torrent
#

Hi there

#

Can you share the part of your code that tries to create the Checkout Session? Be sure to omit any API keys

#

I suspect this is a syntax issue

cloud mirage
#

Sure.

#

This is the original code:

public async createCheckoutSession(
checkoutSessionParams: StripeInfo.CheckoutSessionParams,
): Promise<Stripe.Checkout.Session> {
const successUrl = this.config.get('MY_SUCCESS_URL');
const cancelUrl = this.config.get('MY_CANCEL_URL');
const response = await this.stripe.checkout.sessions.create({
mode: 'subscription',
customer: checkoutSessionParams.customerId,
line_items: checkoutSessionParams.lineItems,
client_reference_id: checkoutSessionParams.clientReferenceId,
success_url: ${successUrl}?session_id={CHECKOUT_SESSION_ID},
cancel_url: cancelUrl,
subscription_data: {
trial_period_days: 14
}
});

return response;

}

#

I have also tried the following:

public async createCheckoutSession(
checkoutSessionParams: StripeInfo.CheckoutSessionParams,
): Promise<Stripe.Checkout.Session> {
const successUrl = this.config.get('MY_SUCCESS_URL');
const cancelUrl = this.config.get('MY_CANCEL_URL');
const response = await this.stripe.checkout.sessions.create({
mode: 'subscription',
customer: checkoutSessionParams.customerId,
line_items: checkoutSessionParams.lineItems,
client_reference_id: checkoutSessionParams.clientReferenceId,
success_url: ${successUrl}?session_id={CHECKOUT_SESSION_ID},
cancel_url: cancelUrl,
subscription_data: {
trial_period_days: 14,
items: checkoutSessionParams.lineItems
}
});

return response;

}

#

Both of those generate the same error. And before I added the subscription_data property, that function was working correctly.

ripe torrent
#

before I added the subscription_data property, that function was working correctly
Do you have a Session ID for one that succeeded?

#

line_items should be an array of hashes. Do you know what type checkoutSessionParams.lineItems is?

cloud mirage
#

This is the ID for a successful Checkout Session ID: cs_test_a1XItWj9SpFisBuiLapRTtTnXdZCeWVdbZyQTgccUJoFifloQCBuzkhOpi

#

checkoutSessionParams.lineItems is of type Array<PriceLineItem> and PriceLineItem has the following type:

export interface PriceLineItem {
id?: string,
price: string,
quantity?: number
}

#

In this particular case, I am only passing price (the id of the price not, the Price object) and the quantity

#

And as soon as I put the 'items' property inside 'subscription_data', TypeScript raises the following error:

No overload matches this call.
Overload 1 of 2, '(params?: SessionCreateParams, options?: RequestOptions): Promise<Response<Session>>', gave the following error.
Object literal may only specify known properties, and 'items' does not exist in type 'SubscriptionData'.
Overload 2 of 2, '(options?: RequestOptions): Promise<Response<Session>>', gave the following error.
Object literal may only specify known properties, and 'mode' does not exist in type 'RequestOptions'.ts(2769)
SessionsResource.d.ts(240, 9): The expected type comes from property 'subscription_data' which is declared here on type 'SessionCreateParams'

ripe torrent
#

Can you share with me what you're trying to do exactly?

cloud mirage
#

I just want to create a checkout session for a subscription and configure 14 days of trial period. At the beginning I did NOT include the items, because I was following the docs and as you say, there is no reference about items anywhere. However, after I called the function with the subscription_data and the trial_period_days inside it, Stripe started responding with this error:

ERROR [ExceptionsHandler] Missing required param: subscription_data[items].
Error: Missing required param: subscription_data[items].

#

I know that 'items' in 'subscription_data' is no longer supported, but I don't understand why is Stripe throwing an error because of that.

#

As I mentioned before, the checkout session creation was working just fine until I decided to put the subscription_data with the trial_period_days.

#

An according to the logs in Stripe Dashboard, the request to POST /v1/checkout/sessions was made using Stripe API version 2024-06-20

ripe torrent
cloud mirage
#

No. I am sending the line_items

ripe torrent
#

Hm, I think that error message could be clearer

cloud mirage
#

If you check the code I sent, the line_items are there

ripe torrent
#

Still, I think the error message could be clearer here since it's not subscription_data[items] that's missing

cloud mirage
#

Yes. You are totally right. Something happened with the line_items.

#

Thank you.

ripe torrent
#

Sure thing!

cloud mirage
#

And yes, the error message should be updated ๐Ÿ˜…

#

Thanks again, man.

ripe torrent
#

Sure thing!