import { KEYS, store } from '@/lib/storage'; /** برگشت از درگاهِ پرداخت: سرور کاربر را به `/?orderId=…&status=…` برمی‌گرداند. */ export interface PaymentReturn { orderId: string; status: string; } /** * پارامترهای آدرسِ ورود را یک‌بار می‌خواند و از نوارِ آدرس پاک می‌کند، تا با * رفرش دوباره پیامِ پرداخت نشان داده نشود: * ?ref=CODE کدِ معرف (لینکِ دعوت) * ?orderId=…&status=… نتیجه‌ی پرداخت */ function readLaunchParams(): PaymentReturn | null { const params = new URLSearchParams(window.location.search); const ref = params.get('ref'); const orderId = params.get('orderId'); const status = params.get('status'); if (ref) store.set(KEYS.referralCode, ref.slice(0, 40)); if (ref || orderId) { window.history.replaceState(null, '', window.location.pathname); } return orderId ? { orderId, status: status ?? '' } : null; } /** یک‌بار، هنگامِ بار شدنِ اپ. */ export const launchPayment = readLaunchParams();