stripe
This commit is contained in:
parent
853234eb2f
commit
6b35b91ab1
3 changed files with 26 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ import {
|
|||
processedStripeEvents,
|
||||
} from "@/lib/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { getXeroClient } from "@/lib/xero/service";
|
||||
|
||||
|
||||
const stripe = getStripe();
|
||||
|
|
@ -111,7 +112,7 @@ export async function POST(req: NextRequest) {
|
|||
// --------------------------------------------------
|
||||
// 5️⃣ Init Xero client + refresh token if needed
|
||||
// --------------------------------------------------
|
||||
const xero = new XeroClient();
|
||||
const xero = getXeroClient();
|
||||
|
||||
xero.setTokenSet({
|
||||
access_token: xeroConn.accessToken,
|
||||
|
|
|
|||
19
stripe_to_invoice/lib/stripe/service.ts
Normal file
19
stripe_to_invoice/lib/stripe/service.ts
Normal 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;
|
||||
}
|
||||
5
stripe_to_invoice/lib/xero/service.ts
Normal file
5
stripe_to_invoice/lib/xero/service.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { XeroClient } from "xero-node";
|
||||
|
||||
export function getXeroClient(): XeroClient {
|
||||
return new XeroClient();
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue