From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Creating checkout session dynamically

Creating checkout session dynamically

In this lecture, we will create a checkout session with the logged in customers data and the list of products with which the customer has checked out. So I will go to the checkout component and receive cart items and customer data from the use product context hook. And I will pass them to the createCheckoutSession action. Now I will go to the StripeActions.js file and receive them in the createCheckoutSession function as products and customer data. Next I will replace all the static values with the dynamic values. So CustomerEmail will be CustomerData.Email. Then LineItems will be Products.Map, will receive individual product here. I will shift the code here and change the product's name with Product.Name along with Size to Product.Size. Then unit amount will be parseInt product.sellPrice into 100 and then quantity product.quantity. Now I will add metadata attribute in the configuration. So we'll say metadata. Then we'll add the product's value as string. So products JSON.stringify…

Contents