'use client'; import React, { useState } from 'react'; import { PaymentElement, useStripe, useElements, } from '@stripe/react-stripe-js'; import { Loader2, Lock, ShieldCheck, HelpCircle } from 'lucide-react'; interface CheckoutFormProps { amount: number; currency: string; callbackUrl: string; piId: string; } export default function CheckoutForm({ amount, currency, callbackUrl, piId }: CheckoutFormProps) { const stripe = useStripe(); const elements = useElements(); const [message, setMessage] = useState(null); const [isLoading, setIsLoading] = useState(false); const [name, setName] = useState(''); const [phone, setPhone] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!stripe || !elements) { return; } if (!name || !phone) { setMessage("Lütfen ad soyad ve telefon numaranızı giriniz."); return; } setIsLoading(true); // 1. Update customer info in our database try { await fetch('/api/update-transaction-info', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ stripe_id: piId, customer_name: name, customer_phone: phone, }), }); } catch (err) { console.error('Info update error:', err); } // 2. Confirm payment in Stripe const { error } = await stripe.confirmPayment({ elements, confirmParams: { return_url: `${window.location.origin}/checkout/success?callback_url=${encodeURIComponent(callbackUrl)}`, payment_method_data: { billing_details: { name: name, phone: phone, } } }, }); if (error.type === "card_error" || error.type === "validation_error") { setMessage(error.message ?? "Bir hata oluştu."); } else { setMessage("Beklenmedik bir hata oluştu."); } setIsLoading(false); }; return (

TOPLAM TUTAR

{amount.toLocaleString('tr-TR', { minimumFractionDigits: 2 })} {currency.toUpperCase() === 'TRY' || currency.toUpperCase() === 'TL' ? '₺' : currency.toUpperCase()}

Güvenli ve Şifreli İşlem

{/* Customer Details */}
setName(e.target.value)} className="w-full p-4 bg-gray-50 border border-gray-200 rounded-2xl text-gray-900 focus:ring-2 focus:ring-blue-500 outline-none text-sm font-bold" required />
setPhone(e.target.value)} className="w-full p-4 bg-gray-50 border border-gray-200 rounded-2xl text-gray-900 focus:ring-2 focus:ring-blue-500 outline-none text-sm font-bold" required />
{message && (
{message}
)}

256-BIT SSL ŞİFRELİ İŞLEM

Stripe GÜVENCESİYLE
PCI DSS UYUMLU
); }