import path from 'path'; import { buildConfig } from 'payload'; import { postgresAdapter } from '@payloadcms/db-postgres'; import { lexicalEditor } from '@payloadcms/richtext-lexical'; import { stripePlugin } from '@payloadcms/plugin-stripe'; import { Users } from './payload/collections/Users'; import { Products } from './payload/collections/Products'; import { Prices } from './payload/collections/Prices'; import { Subscriptions } from './payload/collections/Subscriptions'; import { Customers } from './payload/collections/Customers'; import { BibleBooks } from './payload/collections/BibleBooks'; import { BibleVerses } from './payload/collections/BibleVerses'; import { Bookmarks } from './payload/collections/Bookmarks'; import { Highlights } from './payload/collections/Highlights'; import { Donations } from './payload/collections/Donations'; import { CheckoutSessions } from './payload/collections/CheckoutSessions'; import { FailedPayments } from './payload/collections/FailedPayments'; import { SiteSettings } from './payload/globals/SiteSettings'; export default buildConfig({ secret: process.env.PAYLOAD_SECRET || 'development-secret', admin: { user: Users.slug, livePreview: { breakpoints: [ { label: 'Mobile', name: 'mobile', width: 375, height: 667, }, { label: 'Tablet', name: 'tablet', width: 1024, height: 768, }, { label: 'Desktop', name: 'desktop', width: 1440, height: 900, }, ], }, meta: { titleSuffix: '- Biblical Guide', }, }, editor: lexicalEditor(), collections: [ Users, Customers, Subscriptions, Products, Prices, BibleBooks, BibleVerses, Bookmarks, Highlights, Donations, CheckoutSessions, FailedPayments, ], globals: [SiteSettings], plugins: [ stripePlugin({ stripeSecretKey: process.env.STRIPE_SECRET_KEY || '', stripeWebhooksEndpointSecret: process.env.STRIPE_WEBHOOK_SECRET || '', webhooks: { 'checkout.session.completed': async ({ event, payload: payloadInstance }) => { console.log('Stripe webhook: checkout.session.completed', event.id); // Webhook handling will be in separate file }, 'customer.subscription.created': async ({ event }) => { console.log('Stripe webhook: customer.subscription.created', event.id); }, 'customer.subscription.updated': async ({ event }) => { console.log('Stripe webhook: customer.subscription.updated', event.id); }, 'customer.subscription.deleted': async ({ event }) => { console.log('Stripe webhook: customer.subscription.deleted', event.id); }, }, sync: [], }), ], db: postgresAdapter({ pool: { connectionString: process.env.DATABASE_URL, }, }), typescript: { outputFile: path.resolve(__dirname, 'types/payload-types.ts'), }, routes: { admin: '/admin/payload', api: '/api/payload', }, localization: { locales: ['en', 'ro', 'es', 'it'], defaultLocale: 'en', fallback: true, }, upload: { limits: { fileSize: 5000000, // 5MB }, }, onInit: async (payload) => { console.log('Payload initialized'); // Check if we need to run migrations const adminUsers = await payload.find({ collection: 'users', where: { role: { equals: 'admin', }, }, limit: 1, }); if (adminUsers.totalDocs === 0) { console.log('No admin user found. Please create one via the admin panel.'); } }, });