import { inAndroidApp } from './bazaar'; export type PaymentMethod = 'zarinpal' | 'bazaar'; const KNOWN: PaymentMethod[] = ['zarinpal', 'bazaar']; /** * پیش‌فرض: در مرورگر فقط زرین‌پال (خریدِ بازار بیرون از اپِ اندروید ممکن نیست)، داخلِ اپ هر دو، زرین‌پال اول. * برای نسخه‌ای که فقط در کافه‌بازار منتشر می‌شود، `app: ["bazaar"]` در dist/config.js؛ build لازم نیست. */ const DEFAULTS: Record<'web' | 'app', PaymentMethod[]> = { web: ['zarinpal'], app: ['zarinpal', 'bazaar'], }; /** * روش‌های پرداختِ این‌جا (مرورگر یا اپ)، به ترتیبِ نمایش. نامِ ناشناخته در config.js نادیده گرفته نمی‌شود که * بی‌صدا یک روش گم شود: در کنسول خطا می‌دهد و فهرستِ پیش‌فرض به کار می‌رود. */ export function enabledPaymentMethods(): PaymentMethod[] { const channel = inAndroidApp() ? 'app' : 'web'; const configured = window.__TADRISINO_CONFIG__?.paymentMethods?.[channel]; if (!configured) return DEFAULTS[channel]; const unknown = configured.filter((m) => !KNOWN.includes(m as PaymentMethod)); if (unknown.length || !configured.length) { console.error(`config.js: paymentMethods.${channel} نامعتبر است`, configured); return DEFAULTS[channel]; } return configured as PaymentMethod[]; }