javascript – Next JS How to pass data to getStaticProps – Code Utility


I’m using Next Context to keep a ‘shopping cart’ data persisting to a number of pages in my app. I have an object not unlike this:

 product: 'A product'
 price: 350,
 payment type: 'Deposit'

I can successfully get to this data on any pages so that the user can see which product they have chosen etc. My problem is that when the price is set (depends on whether user chooses full or deposit payment), I need to move them to another page where I need to get a Stripe paymentIntent for the amount before I can take a payment. I need to do that in advance of them actually paying, so the code to get the paymentIntent goes into a ‘getServerSideProps’ request on the next page like this:

export const getServerSideProps = () => {
    const stripe = new Stripe('secret_key')
    const paymentIntent = await stripe.paymentIntents.create({
        amount: AMOUNT_HERE,
        currency: 'gbp'

How can I get my AMOUNT_HERE to show up? Can I use context to somehow bring in the current ‘cart’ object somehow. I’m lost as to how to send the data without having it in the url as variables. I need to make the paymentIntent request before they can pay, but I need to get their data from my context somehow. Is that possible from getServersideProps()? If not, what is the pattern for this type of behaviour. I’m new to Next JS and React so not sure if I’m making the right choices here.