This commit is contained in:
Jun-te Kim 2026-01-20 23:25:03 +00:00
parent 853234eb2f
commit 6b35b91ab1
3 changed files with 26 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import {
processedStripeEvents, processedStripeEvents,
} from "@/lib/schema"; } from "@/lib/schema";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { getXeroClient } from "@/lib/xero/service";
const stripe = getStripe(); const stripe = getStripe();
@ -111,7 +112,7 @@ export async function POST(req: NextRequest) {
// -------------------------------------------------- // --------------------------------------------------
// 5⃣ Init Xero client + refresh token if needed // 5⃣ Init Xero client + refresh token if needed
// -------------------------------------------------- // --------------------------------------------------
const xero = new XeroClient(); const xero = getXeroClient();
xero.setTokenSet({ xero.setTokenSet({
access_token: xeroConn.accessToken, access_token: xeroConn.accessToken,

View file

@ -0,0 +1,19 @@
import Stripe from "stripe";
let stripe: Stripe | null = null;
/**
* Server-only Stripe client.
* Lazy-initialised to avoid build-time crashes.
*/
export function getStripe(): Stripe {
if (!process.env.STRIPE_SECRET_KEY) {
throw new Error("STRIPE_SECRET_KEY missing");
}
if (!stripe) {
stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
}
return stripe;
}

View file

@ -0,0 +1,5 @@
import { XeroClient } from "xero-node";
export function getXeroClient(): XeroClient {
return new XeroClient();
}