#angelcervera

1 messages ยท Page 1 of 1 (latest)

upbeat zenithBOT
narrow crow
#

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

#

And they create the Checkout Session the same was as in our Node docs

heady heath
#

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.

narrow crow
#

How many line items do you have? hard coding isn't messy if you just have a couple

heady heath
#

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

narrow crow
#

Got it

heady heath
#
  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.