Skip to content
Advertisement

cannot pass items and prices into stripe checkout

I am using the embedded nodejs/javascript Stripe Checkout for my custom ecommerce site. I have my own cart created using DB2, and want to pass the name of the products the customer has in the cart, and the matching prices for each product. Stripe is not very clear on how to do this, and i’ve been struggling to find the right way. I am trying right now to use an 2 arrays, (product array and price array) and am trying to pass them into Stripe function, but no luck. here’s the code.

JavaScript

});

please let me know if anyone has tried to do this before, there isn’t much about it online… also, sorry for the messy code…

Advertisement

Answer

A few things here:

  1. product_data is what you’d use if you want to dynamically create a product in-line. Normally you’d create these beforehand on your dashboard. If you still need to create these dynamically, you should follow the object shape described here: https://stripe.com/docs/api/checkout/sessions/create?lang=node#create_checkout_session-line_items-price_data-product_data

  2. unit_amount needs to be an integer. parseFloat(priceArray) will parse the first value of priceArray and ignore the rest, which is presumably not what you’re trying to do here

  3. If you’re trying to create multiple prices, each with its own product and unit_amount, then you need to create an entry in line_items for each. Something like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement