67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
/**
|
||
* salon 服务配置 - PocketBase、支付
|
||
* 使用 site_id=salon,支付调用 payjsapi /salon/*
|
||
*/
|
||
|
||
import { resolvePaymentApiUrl } from "./domain.config";
|
||
|
||
const isDev = process.env.NODE_ENV === "development";
|
||
const PAYJSAPI_PORT = process.env.PAYJSAPI_PORT || "8007";
|
||
|
||
export const SITE_ID = "salon";
|
||
|
||
export const MEETUP_JOIN_AMOUNT = 8800;
|
||
|
||
export function getApiUrlFromRequest(hostHeader: string | null): string | null {
|
||
if (!hostHeader) return null;
|
||
if (!isDev) return resolvePaymentApiUrl();
|
||
const hostname = hostHeader.split(":")[0];
|
||
return `http://${hostname}:${PAYJSAPI_PORT}`;
|
||
}
|
||
|
||
export interface PocketBaseConfig {
|
||
enabled: boolean;
|
||
url: string;
|
||
usersCollection: string;
|
||
joinCollection: string;
|
||
}
|
||
|
||
export interface PaymentConfig {
|
||
enabled: boolean;
|
||
apiUrl: string;
|
||
provider: "zpay" | "xorpay";
|
||
defaultAmount: number;
|
||
defaultType: string;
|
||
zpaySubmitUrl: string;
|
||
}
|
||
|
||
export function getPocketBaseConfig(): PocketBaseConfig {
|
||
return {
|
||
enabled: true,
|
||
url:
|
||
process.env.NEXT_PUBLIC_POCKETBASE_URL ||
|
||
process.env.POCKETBASE_URL ||
|
||
"http://127.0.0.1:8090",
|
||
usersCollection: "users",
|
||
joinCollection: "solanRed",
|
||
};
|
||
}
|
||
|
||
export function getPaymentConfig(): PaymentConfig {
|
||
return {
|
||
enabled: true,
|
||
apiUrl: resolvePaymentApiUrl(),
|
||
provider: (process.env.PAYMENT_PROVIDER as "zpay" | "xorpay") || "zpay",
|
||
defaultAmount: Number(process.env.PAYMENT_DEFAULT_AMOUNT) || 8800,
|
||
defaultType: "salon",
|
||
zpaySubmitUrl: process.env.ZPAY_SUBMIT_URL || "https://zpayz.cn/submit.php",
|
||
};
|
||
}
|
||
|
||
export function getJoinPaymentConfig(): { amount: number; type: string } {
|
||
return {
|
||
amount: Number(process.env.PAYMENT_JOIN_AMOUNT) || MEETUP_JOIN_AMOUNT,
|
||
type: "salon",
|
||
};
|
||
}
|