During the development of my stripe checkout session, I encountered an issue where I can successfully send information to my webhook and print out all the session details, but I am unable to access individual pieces of information. Whenever I try to access a specific line to save it in my backend using prisma, the information appears as undefined when I console.log it. It's puzzling that I can see the entire session but not the specific details. Can anyone point out what I might be doing wrong and how I can access the individual data in my Next.js program?
Here is a snippet of my webhook code
import Stripe from "stripe";
import { stripe } from "@/lib/stripe";
import { headers } from "next/headers";
import { NextResponse } from "next/server";
import prisma from "@/lib/db/prisma";
import { OrderItem } from "@prisma/client";
import { createCart, getCart } from "@/lib/db/cart";
import { revalidatePath } from "next/cache";
... (rest of the code snippet)
When I log the entire session object, it appears as below:
{
... (session details)
}
The issue arises when I attempt to access a specific information like
console.log(session.shipping_details?.address?.state);
which gives an undefined output. Additionally, I noticed that when trying to access keys within the session object, the autocomplete feature does not display basic shipping properties; instead, it only shows shipping_details, which adds to the confusion. While I can access top-level keys like session.created, deeper nested keys do not seem to work as expected. I have exhaustively console.logged various possibilities and referred to the documentation without finding a solution. Any insights would be greatly appreciated.