지피티

Pasted Oct 23, 2026, 1:19 AM1 file88 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/zzgsp6hhpmgfzx2k
제목없음
(async function () {
  const LOCK_KEY = "__chatgptCheckoutCreating";
  if (window[LOCK_KEY]) {
    alert("체크아웃 생성이 이미 진행 중입니다.");
    return;
  }
  window[LOCK_KEY] = true;

  async function fetchJson(url, options = {}, timeoutMs = 15000) {
    const controller = new AbortController();
    const timer = setTimeout(() => controller.abort(), timeoutMs);
    try {
      const response = await fetch(url, {
        credentials: "include",
        cache: "no-store",
        ...options,
        signal: controller.signal
      });
      const raw = await response.text();
      let data = {};
      if (raw) {
        try {
          data = JSON.parse(raw);
        } catch {
          data = { message: raw.slice(0, 500) };
        }
      }
      if (!response.ok) {
        const detail = data?.detail ?? data?.error?.message ?? data?.message ?? raw.slice(0, 300) ?? response.statusText;
        const message = typeof detail === "string" ? detail : JSON.stringify(detail);
        throw new Error(`${response.status} ${response.statusText}: ${message}`);
      }
      return data;
    } finally {
      clearTimeout(timer);
    }
  }

  try {
    if (!location.href.startsWith("https://chatgpt.com")) {
      throw new Error("chatgpt.com에 로그인한 상태에서 실행해 주세요.");
    }
    const session = await fetchJson("/api/auth/session");
    const accessToken = session?.accessToken;
    if (typeof accessToken !== "string" || !accessToken) {
      throw new Error("로그인 세션을 찾지 못했습니다. 다시 로그인해 주세요.");
    }
    const payload = {
      billing_details: {
        country: "KR",
        currency: "PHP"
      },
      checkout_ui_mode: "hosted",
      entry_point: "all_plans_pricing_modal",
      plan_name: "chatgptprolite"
    };
    const checkout = await fetchJson(
      "/backend-api/payments/checkout",
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${accessToken}`,
          "Content-Type": "application/json",
          Accept: "application/json"
        },
        body: JSON.stringify(payload)
      }
    );
    const checkoutId = checkout?.checkout_session_id;
    if (typeof checkoutId !== "string" || !/^[A-Za-z0-9_-]+$/.test(checkoutId)) {
      throw new Error(`유효한 체크아웃 세션이 반환되지 않았습니다: ${JSON.stringify(checkout)}`);
    }
    const checkoutUrl = new URL(
      `/checkout/openai_llc/${encodeURIComponent(checkoutId)}`,
      location.origin
    );
    location.assign(checkoutUrl.href);
  } catch (error) {
    const message = error?.name === "AbortError" 
      ? "요청 시간이 초과되었습니다." 
      : error instanceof Error 
        ? error.message 
        : String(error);
    alert(`체크아웃 생성 실패:\n${message}`);
  } finally {
    window[LOCK_KEY] = false;
  }
})();

2,702 chars · codepastes.com