Initial upload of BB-Apartment 2026 website.

Adds the complete Next.js website including i18n routing, house and
apartment pages, Beds24 v2 integration for live availability/pricing,
Stripe checkout, contact forms, Docker setup and deployment docs.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Markus
2026-08-19 22:54:49 +02:00
co-authored by Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent 232770afe7
commit 2b24334bfa
153 changed files with 5621 additions and 176 deletions
+103
View File
@@ -0,0 +1,103 @@
import { NextRequest, NextResponse } from "next/server";
import { getAvailability, getEffectiveMinStay } from "@/src/lib/beds24";
import { calculatePrice } from "@/src/lib/pricing";
import { getApartmentBySlug, bookingConfig } from "@/src/config/apartments";
import { nightsBetween, addDays } from "@/src/lib/date";
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const apartmentSlug = searchParams.get("apartmentSlug");
const start = searchParams.get("start");
const end = searchParams.get("end");
if (!apartmentSlug || !start || !end) {
return NextResponse.json(
{ error: "Missing required parameters: apartmentSlug, start, end" },
{ status: 400 }
);
}
const apartment = getApartmentBySlug(apartmentSlug);
if (!apartment) {
return NextResponse.json(
{ error: "Apartment not found" },
{ status: 404 }
);
}
const nights = nightsBetween(start, end);
if (nights <= 0) {
return NextResponse.json(
{ error: "End date must be after start date" },
{ status: 400 }
);
}
const minStayNights = await getEffectiveMinStay(
apartment.houseId,
apartment.beds24PropertyId,
apartment.beds24RoomId,
start,
bookingConfig.minStayNights
);
const minStayValid = nights >= minStayNights;
const availability = await getAvailability({
houseId: apartment.houseId,
propertyId: apartment.beds24PropertyId,
roomId: apartment.beds24RoomId,
start,
end,
});
// Fetch Beds24's own short-stay rate for the same arrival date, purely to
// display a genuine "savings vs. short-term rate" figure — this never
// changes the actual price charged (see calculatePrice()).
let referenceNightlyRate: number | undefined;
if (availability.available && nights > bookingConfig.referenceStayNights) {
try {
const reference = await getAvailability({
houseId: apartment.houseId,
propertyId: apartment.beds24PropertyId,
roomId: apartment.beds24RoomId,
start,
end: addDays(start, bookingConfig.referenceStayNights),
});
if (reference.available) {
referenceNightlyRate = reference.price;
}
} catch (referenceError) {
console.error("Reference price lookup failed:", referenceError);
}
}
const price = calculatePrice(
availability.price,
nights,
availability.currency,
referenceNightlyRate
);
return NextResponse.json({
apartmentSlug,
start,
end,
nights,
available: availability.available,
minStayValid,
minStayNights,
maxGuests: apartment.maxGuests,
price,
});
} catch (error) {
console.error("Availability API error:", error);
return NextResponse.json(
{ error: "Failed to fetch availability" },
{ status: 500 }
);
}
}
+162
View File
@@ -0,0 +1,162 @@
import { NextRequest, NextResponse } from "next/server";
import { getStripe, getStripeAccountId } from "@/src/lib/stripe";
import { prisma } from "@/src/lib/prisma";
import { getApartmentBySlug, bookingConfig } from "@/src/config/apartments";
import { getAvailability, getEffectiveMinStay } from "@/src/lib/beds24";
import { calculatePrice } from "@/src/lib/pricing";
import { nightsBetween } from "@/src/lib/date";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const {
apartmentSlug,
start,
end,
guestEmail,
guestName,
successUrl,
cancelUrl,
} = body;
if (!apartmentSlug || !start || !end || !guestEmail || !guestName) {
return NextResponse.json(
{ error: "Missing required booking parameters" },
{ status: 400 }
);
}
const apartment = getApartmentBySlug(apartmentSlug);
if (!apartment) {
return NextResponse.json(
{ error: "Apartment not found" },
{ status: 404 }
);
}
const startDate = new Date(start);
const endDate = new Date(end);
const nights = nightsBetween(start, end);
const minStayNights = await getEffectiveMinStay(
apartment.houseId,
apartment.beds24PropertyId,
apartment.beds24RoomId,
start,
bookingConfig.minStayNights
);
if (nights < minStayNights) {
return NextResponse.json(
{ error: `Minimum stay is ${minStayNights} nights` },
{ status: 400 }
);
}
const availability = await getAvailability({
houseId: apartment.houseId,
propertyId: apartment.beds24PropertyId,
roomId: apartment.beds24RoomId,
start,
end,
});
if (!availability.available) {
return NextResponse.json(
{ error: "Apartment not available for selected dates" },
{ status: 409 }
);
}
const price = calculatePrice(availability.price, nights, availability.currency);
const depositAmount = Math.round(price.depositAmount * 100); // cents
const stripe = getStripe(apartment.houseId);
const accountId = getStripeAccountId(apartment.houseId);
// Create or update Stripe customer
let customer;
const existingCustomers = await stripe.customers.list({
email: guestEmail,
limit: 1,
});
if (existingCustomers.data.length > 0) {
customer = existingCustomers.data[0];
} else {
customer = await stripe.customers.create({
email: guestEmail,
name: guestName,
});
}
const bookingReference = `BB-${Date.now()}-${Math.random().toString(36).substring(2, 7).toUpperCase()}`;
// Create pending booking in database
await prisma.booking.create({
data: {
bookingReference,
apartmentSlug,
houseId: apartment.houseId,
beds24PropertyId: apartment.beds24PropertyId,
beds24RoomId: apartment.beds24RoomId,
guestEmail,
guestName,
checkIn: startDate,
checkOut: endDate,
nights,
totalAmount: price.totalAfterDiscount,
depositAmount: price.depositAmount,
currency: price.currency,
status: "pending",
stripeAccountId: accountId,
stripeCustomerId: customer.id,
},
});
const session = await stripe.checkout.sessions.create({
customer: customer.id,
payment_method_types: ["card"],
line_items: [
{
price_data: {
currency: price.currency.toLowerCase(),
product_data: {
name: `Anzahlung Apartment ${apartment.name}`,
description: `Aufenthalt: ${start} bis ${end} (${nights} Nächte)`,
},
unit_amount: depositAmount,
},
quantity: 1,
},
],
mode: "payment",
success_url: successUrl || `${process.env.NEXT_PUBLIC_BASE_URL}/de/booking-success?reference=${bookingReference}`,
cancel_url: cancelUrl || `${process.env.NEXT_PUBLIC_BASE_URL}/de/apartments/${apartmentSlug}`,
metadata: {
bookingReference,
apartmentSlug,
houseId: apartment.houseId,
},
});
await prisma.booking.update({
where: { bookingReference },
data: { stripeCheckoutSessionId: session.id },
});
return NextResponse.json({
sessionId: session.id,
bookingReference,
url: session.url,
});
} catch (error) {
console.error("Checkout session error:", error);
return NextResponse.json(
{ error: "Failed to create checkout session" },
{ status: 500 }
);
}
}
+27
View File
@@ -0,0 +1,27 @@
import { NextRequest, NextResponse } from "next/server";
import { sendContactMessage } from "@/src/lib/mail";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
try {
const { name, email, message, context } = await request.json();
if (!email || !message) {
return NextResponse.json(
{ error: "Missing required fields: email, message" },
{ status: 400 }
);
}
await sendContactMessage({ name, email, message, context });
return NextResponse.json({ success: true });
} catch (error) {
console.error("Contact API error:", error);
return NextResponse.json(
{ error: "Failed to send message" },
{ status: 500 }
);
}
}
+44
View File
@@ -0,0 +1,44 @@
import { NextRequest, NextResponse } from "next/server";
import { getEffectiveMinStay } from "@/src/lib/beds24";
import { getApartmentBySlug, bookingConfig } from "@/src/config/apartments";
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const apartmentSlug = searchParams.get("apartmentSlug");
const arrival = searchParams.get("arrival");
if (!apartmentSlug || !arrival) {
return NextResponse.json(
{ error: "Missing required parameters: apartmentSlug, arrival" },
{ status: 400 }
);
}
const apartment = getApartmentBySlug(apartmentSlug);
if (!apartment) {
return NextResponse.json(
{ error: "Apartment not found" },
{ status: 404 }
);
}
const minStayNights = await getEffectiveMinStay(
apartment.houseId,
apartment.beds24PropertyId,
apartment.beds24RoomId,
arrival,
bookingConfig.minStayNights
);
return NextResponse.json({ apartmentSlug, arrival, minStayNights });
} catch (error) {
console.error("Min-stay API error:", error);
return NextResponse.json(
{ error: "Failed to determine minimum stay" },
{ status: 500 }
);
}
}
+44
View File
@@ -0,0 +1,44 @@
import { NextRequest, NextResponse } from "next/server";
import { getStripe } from "@/src/lib/stripe";
import { prisma } from "@/src/lib/prisma";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
try {
const { bookingReference, email } = await request.json();
if (!bookingReference || !email) {
return NextResponse.json(
{ error: "Missing bookingReference or email" },
{ status: 400 }
);
}
const booking = await prisma.booking.findUnique({
where: { bookingReference },
});
if (!booking || booking.guestEmail !== email || !booking.stripeCustomerId) {
return NextResponse.json(
{ error: "Booking not found" },
{ status: 404 }
);
}
const stripe = getStripe(booking.houseId);
const session = await stripe.billingPortal.sessions.create({
customer: booking.stripeCustomerId,
return_url: `${process.env.NEXT_PUBLIC_BASE_URL}/de`,
});
return NextResponse.json({ url: session.url });
} catch (error) {
console.error("Portal session error:", error);
return NextResponse.json(
{ error: "Failed to create portal session" },
{ status: 500 }
);
}
}
+38
View File
@@ -0,0 +1,38 @@
import { NextResponse } from "next/server";
import { getRoomInfo } from "@/src/lib/beds24";
import { allApartments } from "@/src/config/apartments";
export const dynamic = "force-dynamic";
export async function GET() {
try {
const rooms = await Promise.all(
allApartments.map(async (apartment) => {
const info = await getRoomInfo(
apartment.houseId,
apartment.beds24PropertyId,
apartment.beds24RoomId
);
return {
slug: apartment.slug,
beds24RoomId: apartment.beds24RoomId,
beds24PropertyId: apartment.beds24PropertyId,
name: apartment.name,
nameEn: apartment.nameEn,
beds24Name: info.name,
maxGuests: info.maxGuests,
minStay: info.minStay,
currency: info.currency,
};
})
);
return NextResponse.json({ rooms });
} catch (error) {
console.error("Rooms API error:", error);
return NextResponse.json(
{ error: "Failed to fetch rooms" },
{ status: 500 }
);
}
}
+80
View File
@@ -0,0 +1,80 @@
import { NextRequest, NextResponse } from "next/server";
import { headers } from "next/headers";
import Stripe from "stripe";
import { getStripe, getStripeWebhookSecret } from "@/src/lib/stripe";
import { prisma } from "@/src/lib/prisma";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
const payload = await request.text();
const headerPayload = await headers();
const signature = headerPayload.get("stripe-signature") || "";
// Determine which Stripe account this webhook belongs to
// Stripe sends the account ID in the Stripe-Account header for Connect
const accountId = headerPayload.get("stripe-account") || "";
let houseId: string;
if (process.env.STRIPE_ACCOUNT_HERDWEWEG && accountId === process.env.STRIPE_ACCOUNT_HERDWEWEG) {
houseId = "herdweg";
} else if (process.env.STRIPE_ACCOUNT_SCHOENAICHER && accountId === process.env.STRIPE_ACCOUNT_SCHOENAICHER) {
houseId = "schoenaicher";
} else {
// If no account header, try to infer from event metadata (not available in signature verification)
// For now, we'll try both secrets. In production, use separate webhook endpoints or account headers.
return NextResponse.json(
{ error: "Could not determine Stripe account" },
{ status: 400 }
);
}
try {
const stripe = getStripe(houseId);
const webhookSecret = getStripeWebhookSecret(houseId);
const event = stripe.webhooks.constructEvent(payload, signature, webhookSecret);
// Deduplicate events
const existingEvent = await prisma.stripeEvent.findUnique({
where: { eventId: event.id },
});
if (existingEvent) {
return NextResponse.json({ received: true });
}
await prisma.stripeEvent.create({
data: {
eventId: event.id,
accountId,
type: event.type,
payload: JSON.stringify(event),
},
});
if (event.type === "checkout.session.completed") {
const session = event.data.object as Stripe.Checkout.Session;
const bookingReference = session.metadata?.bookingReference;
if (bookingReference) {
await prisma.booking.update({
where: { bookingReference },
data: {
status: "deposit_paid",
stripePaymentIntentId: session.payment_intent as string,
},
});
// TODO: Trigger n8n workflow to create booking in Beds24
console.log(`Deposit paid for booking ${bookingReference}`);
}
}
return NextResponse.json({ received: true });
} catch (error) {
console.error("Stripe webhook error:", error);
return NextResponse.json(
{ error: "Webhook verification failed" },
{ status: 400 }
);
}
}