#Issues with stripe integration

2 messages · Page 1 of 1 (latest)

cobalt cosmos
#

Good Afternoon, I am currently having some issues integrating stripe into my webpage. I am able of making the checkout form and redirecting it to a return page, but I can't seem to retrieve the session information, for some reason it is recovering the session_id as null. Can someone help me? I am not sure what is going on. Followed the return page code.

---
import Base from "../layouts/Base.astro";
import Stripe from 'stripe'

export const prenender = false 
const stripe = new Stripe(import.meta.env.STRIPE_KEY)
const sessionID = Astro.url.searchParams.get('session_id')

let session 
try {
  session = await stripe.checkout.sessions.retrieve(sessionID)
} catch (e) {
  return Astro.redirect('/checkout')
}


const { name, email } = session.customer_details
---

<Base>
  <div>
    <h1>Thank you for your purchase, {name}!</h1>
    <p>We've sent a receipt to {email}.</p>
  </div>
</Base>