diff --git a/src/features/odeme/components/iyzico-formu.tsx b/src/features/odeme/components/iyzico-formu.tsx index b75d2b8..abce127 100644 --- a/src/features/odeme/components/iyzico-formu.tsx +++ b/src/features/odeme/components/iyzico-formu.tsx @@ -9,7 +9,7 @@ import { useEffect, useMemo } from "react"; // // iyzico script'i `typeof iyziInit == 'undefined'` koruması taşır: aynı oturumda // ikinci kez mount olursa (geri gel / tekrar dene) global temizlenmezse form -// çizilmez. Bu yüzden enjeksiyondan önce ve unmount'ta global silinir. +// çizilmez. Bu yüzden enjeksiyondan önce ve unmount'ta global sıfırlanır. declare global { interface Window { @@ -17,6 +17,23 @@ declare global { } } +// iyzico bundle'ı `iyziInit`i global `var` ile tanımlıyor; bu da property'yi +// non-configurable yapıyor, yani `delete window.iyziInit` strict mode'da +// TypeError fırlatıyor ("Cannot delete property 'iyziInit'"). Önce silmeyi +// dene, olmazsa undefined ata — script'in aradığı `typeof ... == 'undefined'` +// koşulu iki yolla da sağlanır. +function iyziInitSifirla() { + try { + delete window.iyziInit; + } catch { + try { + window.iyziInit = undefined; + } catch { + // global kilitliyse yapacak bir şey yok; form yine de çizilmeye çalışılır + } + } +} + export function IyzicoFormu({ icerik }: { icerik: string }) { const govde = useMemo( () => icerik.match(/]*>([\s\S]*?)<\/script>/i)?.[1], @@ -25,13 +42,13 @@ export function IyzicoFormu({ icerik }: { icerik: string }) { useEffect(() => { if (!govde) return; - delete window.iyziInit; + iyziInitSifirla(); const script = document.createElement("script"); script.text = govde; document.body.appendChild(script); return () => { script.remove(); - delete window.iyziInit; + iyziInitSifirla(); }; }, [govde]);