feat(olcum): odeme_hata {kod} olayı — başlatma, form ve sonuç hata dalları
Ödeme başlatma action'ının her hata dalı dal adı taşıyan bir kod döndürür;
istemci bunu odeme_hata {kod, urun} olarak atar. Bağlantı hatası, iyzico
formunun çizilememesi ve başarısız sonuç kartı da aynı olayla ölçülür.
Olayda kişisel veri yok (sipariş no, e-posta, iyzico mesajı gitmez).
rehber_kaydirma olay adı da birliğe eklendi (sonraki commit kullanır).
BACKLOG #7. Seri başlangıcı: bu commit'in canlıya çıktığı gün.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { olay } from "@/lib/analitik";
|
||||
|
||||
// iyzico'nun checkoutFormContent'i tek bir <script> bloğudur; içindeki JS,
|
||||
// sayfadaki #iyzipay-checkout-form div'ine formu (iframe) çizer. React
|
||||
@@ -41,7 +42,10 @@ export function IyzicoFormu({ icerik }: { icerik: string }) {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!govde) return;
|
||||
if (!govde) {
|
||||
olay("odeme_hata", { kod: "form_yuklenemedi" });
|
||||
return;
|
||||
}
|
||||
iyziInitSifirla();
|
||||
const script = document.createElement("script");
|
||||
script.text = govde;
|
||||
|
||||
23
src/features/odeme/components/odeme-hata-olayi.tsx
Normal file
23
src/features/odeme/components/odeme-hata-olayi.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
"use client";
|
||||
|
||||
// Başarısız ödeme sonuç kartının görüntülenmesini `odeme_hata` olarak ölçer.
|
||||
// Sonuç kartı sunucu bileşeni; olay mount sonrası buradan atılır. Yalnız
|
||||
// durum adı gider (sipariş no gitmez); yenileme sayıyı şişirmesin diye oturum
|
||||
// başına durum başına bir kez.
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { olayBirKez } from "@/lib/analitik";
|
||||
|
||||
export function OdemeHataOlayi({
|
||||
durum,
|
||||
}: {
|
||||
/** SiparisDurumu (`@/lib/odeme`): pending | failed | not_found */
|
||||
durum: string;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
const kod = `sonuc_${durum}`;
|
||||
olayBirKez("odeme_hata", { kod }, kod);
|
||||
}, [durum]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { PagePixelDivider } from "@/components/pixel-decor";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { RaporYokCta } from "./rapor-yok-cta";
|
||||
import { OdemeHataOlayi } from "./odeme-hata-olayi";
|
||||
|
||||
export async function OdemeSonucKarti({ siparis }: { siparis?: string }) {
|
||||
// Oturum düşmüşse geri dönüşte ?siparis= kaybolmasın (başarı/unblur deneyimi)
|
||||
@@ -118,6 +119,7 @@ export async function OdemeSonucKarti({ siparis }: { siparis?: string }) {
|
||||
</div>
|
||||
) : (
|
||||
<div className="rounded-2xl border border-red-200 bg-card p-8 shadow-sm">
|
||||
<OdemeHataOlayi durum={durum} />
|
||||
<XCircle className="mx-auto size-12 text-red-500" aria-hidden />
|
||||
<h1 className="mt-4 font-heading text-2xl font-bold">
|
||||
Ödeme tamamlanamadı
|
||||
|
||||
@@ -46,10 +46,13 @@ export function SatinAlForm({
|
||||
try {
|
||||
sonuc = await baslatOdeme(urun);
|
||||
} catch {
|
||||
// Action'a hiç ulaşılamadı (ağ, deploy arası, sunucu çöktü)
|
||||
olay("odeme_hata", { kod: "baglanti", urun });
|
||||
toast.error(BAGLANTI_HATASI);
|
||||
return;
|
||||
}
|
||||
if ("error" in sonuc) {
|
||||
olay("odeme_hata", { kod: sonuc.kod, urun });
|
||||
toast.error(sonuc.error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,22 @@ import { initializeCheckoutForm, initImzaDurumu } from "@/lib/iyzico";
|
||||
// promise'ini reddedip formu RedirectBoundary üzerinden yeniden mount ediyor;
|
||||
// cacheComponents altında /paket gizli <Activity> içinde canlı tutulduğu için
|
||||
// bu yarım kalmış durum geri dönüşte butonu tıklamalara sağır bırakıyordu.
|
||||
export type OdemeBaslatDurum = { error: string } | { yonlendir: string };
|
||||
//
|
||||
// Hata dalları `kod` taşır: istemci bunu `odeme_hata {kod}` olayına koyar
|
||||
// (7 Ağu–12 Eyl arasında ~100 sipariş token alamadı ve hiçbir ölçüm bunu
|
||||
// göstermedi). Kod yalnız dal adıdır; kullanıcıya ait hiçbir değer taşımaz.
|
||||
export type OdemeHataKodu =
|
||||
| "gecersiz_urun"
|
||||
| "paket_aktif"
|
||||
| "paket_yok"
|
||||
| "anahtar_eksik"
|
||||
| "iyzico_istisna"
|
||||
| "iyzico_basarisiz"
|
||||
| "imza_gecersiz";
|
||||
|
||||
export type OdemeBaslatDurum =
|
||||
| { error: string; kod: OdemeHataKodu }
|
||||
| { yonlendir: string };
|
||||
|
||||
const GENEL_HATA =
|
||||
"Ödeme şu anda başlatılamıyor; kartından çekim yapılmadı. Birazdan tekrar dener misin?";
|
||||
@@ -32,7 +47,7 @@ export async function baslatOdeme(
|
||||
// Ucuz senkron doğrulama pahalı oturum turundan önce (argüman client'tan
|
||||
// gelir; tipine güvenilmez)
|
||||
if (product !== "paket" && product !== "topup") {
|
||||
return { error: "Geçersiz ürün." };
|
||||
return { error: "Geçersiz ürün.", kod: "gecersiz_urun" };
|
||||
}
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
@@ -42,10 +57,16 @@ export async function baslatOdeme(
|
||||
// sekmede alındı) gelen istek ikinci kez ücret çekmesin.
|
||||
const kullanici = await getCurrentUser();
|
||||
if (product === "paket" && kullanici?.hasPaket) {
|
||||
return { error: "Paketin zaten aktif; yeniden ödeme alınmadı." };
|
||||
return {
|
||||
error: "Paketin zaten aktif; yeniden ödeme alınmadı.",
|
||||
kod: "paket_aktif",
|
||||
};
|
||||
}
|
||||
if (product === "topup" && !kullanici?.hasPaket) {
|
||||
return { error: "Ek kredi için önce paketi alman gerekiyor." };
|
||||
return {
|
||||
error: "Ek kredi için önce paketi alman gerekiyor.",
|
||||
kod: "paket_yok",
|
||||
};
|
||||
}
|
||||
const urun = URUNLER[product];
|
||||
|
||||
@@ -84,10 +105,10 @@ export async function baslatOdeme(
|
||||
if (err instanceof Error && err.message === "IYZICO_KEYS_MISSING") {
|
||||
// Yapılandırma detayı log'a; kullanıcıya altyapı sızdırmayan mesaj
|
||||
console.error("[odeme] iyzico anahtarları eksik — ödeme başlatılamadı");
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "anahtar_eksik" };
|
||||
}
|
||||
console.error("[odeme] iyzico initialize hatası", err);
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "iyzico_istisna" };
|
||||
}
|
||||
|
||||
if (init.status !== "success" || !init.checkoutFormContent || !init.token) {
|
||||
@@ -99,13 +120,13 @@ export async function baslatOdeme(
|
||||
errorCode: init.errorCode,
|
||||
errorMessage: init.errorMessage,
|
||||
});
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "iyzico_basarisiz" };
|
||||
}
|
||||
|
||||
// Yanıtın bütünlüğü: imza tutmuyorsa kullanıcıyı o ödeme sayfasına yollama.
|
||||
if (initImzaDurumu(init) === "gecersiz") {
|
||||
console.error("[odeme] initialize imzası geçersiz", { orderId });
|
||||
return { error: GENEL_HATA };
|
||||
return { error: GENEL_HATA, kod: "imza_gecersiz" };
|
||||
}
|
||||
|
||||
// Form içeriği de saklanır: /odeme/[siparis] sayfası yenilense bile aynı
|
||||
|
||||
Reference in New Issue
Block a user