#angelcervera
1 messages ยท Page 1 of 1 (latest)
Not super familiar with TypeScript, but I don't think it should be any different than what's shown here: https://stripe.com/docs/api/checkout/sessions/create?lang=node
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You shouldn't need to import anything
Like this should be fine I think:
success_url: 'https://example.com/success',
line_items: [
{price: 'price_1', quantity: 2},
],
mode: 'payment',
});```
The only official Stripe guide or video that uses TypeScript I think is this one: https://www.youtube.com/watch?v=sPUSu19tZHg
Learn how to create Next.js applications in TypeScript and how to benefit from types when implementing Stripe Checkout.
Resources
And they create the Checkout Session the same was as in our Node docs
The problem is how to create the line_items array. line_items is accepting only LineItem object and no idea how to create it. That code is valid in Typescript because the array of items is hardcoded.
In that demo, their are hard coding the list of items as well. ๐
From their repo:
line_items: [
{
name: 'Custom amount donation',
amount: formatAmountForStripe(amount, CURRENCY),
currency: CURRENCY,
quantity: 1,
},
],
But thanks for the link.
How many line items do you have? hard coding isn't messy if you just have a couple
I don't know. The list is always dynamic. It is the client who is buying, so how to know it? ๐
Any way, I think that found the definition: Stripe.Checkout.SessionCreateParams.LineItem
Got it
const linesOfItems: Stripe.Checkout.SessionCreateParams.LineItem[] = cart.map((item) => {
const line: Stripe.Checkout.SessionCreateParams.LineItem = {
price: item.price,
quantity: item.quantity,
}
return line;
});
That is the way, I suppose. Thanks for the link. It leaded me to the right path.