#juan-pablo_api
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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
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.
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?
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'
Also, according to the changelog of the Stripe API, the support for items inside subscription_data was removed on November 16 2022: https://docs.stripe.com/changelog#november-16,-2022
Was just about to ask why you're using subscription_data.items since this is not in our docs: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-subscription_data
Can you share with me what you're trying to do exactly?
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
Ah, it looks like you're omitting line_items in these requests: https://dashboard.stripe.com/test/logs/req_6JHyjLCrZkSeh3
No. I am sending the line_items
Hm, I think that error message could be clearer
If you check the code I sent, the line_items are there
Not in this request, check this link: https://dashboard.stripe.com/test/logs/req_6JHyjLCrZkSeh3
Still, I think the error message could be clearer here since it's not subscription_data[items] that's missing
Sure thing!
Sure thing!