Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@payloadcms/db-postgres": "3.79.0",
"@payloadcms/next": "3.79.0",
"@payloadcms/plugin-form-builder": "3.79.0",
"@payloadcms/richtext-lexical": "3.79.0",
"@payloadcms/ui": "3.79.0",
"cross-env": "^7.0.3",
Expand Down
48 changes: 47 additions & 1 deletion cms/src/app/(payload)/admin/importMap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions cms/src/app/stripe/events/checkout/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { NextRequest } from 'next/server'
// import configPromise from '@payload-config'
// import { getPayload } from 'payload'
import Stripe from 'stripe'

// Generic route for all event payments, takes in stripe customer ID and event price ID
export const POST = async (request: NextRequest) => {
let body: {
eventId?: string
customerId?: string
priceId?: string
}
try {
body = await request.json()
} catch {
return Response.json({ error: 'Invalid JSON body' }, { status: 400 })
}

const { customerId, priceId, eventId } = body
if (!customerId || !priceId) {
return Response.json(
{
error: 'Missing required fields: customerId, priceId',
},
{ status: 400 },
)
}

const stripeSecretKey = process.env.STRIPE_SECRET_KEY
const webUrl = process.env.WEB_URL || 'http://localhost:3000'

if (!stripeSecretKey || !priceId) {
return Response.json({ error: 'Stripe not configured' }, { status: 500 })
}

// const payload = await getPayload({ config: configPromise })
const stripe = new Stripe(stripeSecretKey, { apiVersion: '2026-04-22.dahlia' })

try {
const session = await stripe.checkout.sessions.create({
mode: 'payment',
customer: customerId,
line_items: [{ price: priceId, quantity: 1 }],
success_url: `${webUrl}/events/${eventId}/signup/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${webUrl}/events/${eventId}/signup?cancelled=true`,
metadata: { customerId: String(customerId) },
})

if (!session.url) {
return Response.json(
{ error: 'Stripe did not provide a checkout URL for the created session' },
{ status: 502 },
)
}

return Response.json({ checkoutUrl: session.url })
} catch (err: unknown) {
const message = err instanceof Error ? err.message : 'Failed to create Stripe checkout session'
return Response.json({ error: message }, { status: 502 })
}
}
28 changes: 25 additions & 3 deletions cms/src/collections/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { CollectionConfig } from 'payload'

export const Events: CollectionConfig = {
slug: 'events',
access: {
read: () => true,
},
admin: {
useAsTitle: 'title',
},
Expand All @@ -11,6 +14,11 @@ export const Events: CollectionConfig = {
type: 'text',
required: true,
},
{
name: 'eventCost',
type: 'number',
required: false,
},
{
name: 'date',
type: 'date',
Expand All @@ -25,6 +33,14 @@ export const Events: CollectionConfig = {
type: 'upload',
relationTo: 'media',
},
{
name: 'signupForm',
type: 'relationship',
relationTo: 'forms',
admin: {
position: 'sidebar',
},
},
{
name: 'isUpcoming',
type: 'checkbox',
Expand All @@ -41,8 +57,14 @@ export const Events: CollectionConfig = {
type: 'upload',
relationTo: 'media',
required: true,
}
},
],
}
]
},
{
name: 'stripePriceId',
type: 'text',
defaultValue: '',
required: true,
},
],
}
Loading