'use client'; import React, { useState, useEffect } from 'react'; import Link from 'next/link'; import { Plus, Building2, Copy, ExternalLink, MoreVertical, Globe, Check, Pencil, Trash2, X } from 'lucide-react'; export default function MerchantsPage() { const [merchants, setMerchants] = useState([]); const [isLoading, setIsLoading] = useState(true); const [copiedId, setCopiedId] = useState(null); const [isEditModalOpen, setIsEditModalOpen] = useState(false); const [editingMerchant, setEditingMerchant] = useState(null); const [isUpdating, setIsUpdating] = useState(false); useEffect(() => { fetchMerchants(); }, []); const fetchMerchants = async () => { setIsLoading(true); try { const response = await fetch('/api/merchants'); const data = await response.json(); if (!response.ok) throw new Error(data.error); setMerchants(data); } catch (err) { console.error('Fetch error:', err); } finally { setIsLoading(false); } }; const copyToClipboard = (text: string, id: string) => { navigator.clipboard.writeText(text); setCopiedId(id); setTimeout(() => setCopiedId(null), 2000); }; const handleEditClick = (merchant: any) => { setEditingMerchant({ ...merchant }); setIsEditModalOpen(true); }; const handleUpdateMerchant = async (e: React.FormEvent) => { e.preventDefault(); setIsUpdating(true); try { const response = await fetch(`/api/merchants/${editingMerchant.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: editingMerchant.name, webhook_url: editingMerchant.webhook_url, payment_provider: editingMerchant.payment_provider, provider_config: editingMerchant.provider_config }) }); if (!response.ok) throw new Error('Güncelleme başarısız.'); await fetchMerchants(); setIsEditModalOpen(false); setEditingMerchant(null); } catch (err: any) { alert(err.message); } finally { setIsUpdating(false); } }; const handleDeleteMerchant = async (id: string) => { if (!confirm('Bu firmayı silmek istediğinize emin misiniz? Bu işlem geri alınamaz.')) return; try { const response = await fetch(`/api/merchants/${id}`, { method: 'DELETE' }); if (!response.ok) throw new Error('Silme işlemi başarısız.'); await fetchMerchants(); } catch (err: any) { alert(err.message); } }; return (
{/* Header */}

Firmalar (Merchants)

Ödeme alan tüm işletmeler

Yeni Firma Ekle
{/* Merchant Cards Grid */}
{isLoading ? (
) : merchants.map((m) => { const identifier = m.short_id || m.id; const paymentLink = typeof window !== 'undefined' ? `${window.location.origin}/checkout?merchant_id=${identifier}&amount=0` : `https://p2cgateway.store/checkout?merchant_id=${identifier}&amount=0`; return (
{m.name.substring(0, 1).toUpperCase()}

{m.name}

ID: {identifier} {m.short_id && Short Link Active}
{/* API Key Section */}
{m.api_key || '••••••••••••••••'}
{/* Webhook Section */}
{m.webhook_url || 'Ayarlanmamış'}
{/* Payment Link Section */}
{paymentLink}

Bu linki tutar ve referans ekleyerek değiştirebilirsiniz.

Aktif
Tüm İşlemleri Gör Firma Paneli
); })} {!isLoading && merchants.length === 0 && (

Henüz firma bulunmuyor

İlk firmanızı ekleyerek ödeme almaya başlayın.

Firma Ekleyerek Başlayın
)}
{/* Edit Modal */} {isEditModalOpen && (

Firmayı Düzenle

Firma bilgilerini güncelle

setEditingMerchant({ ...editingMerchant, name: e.target.value })} placeholder="Örn: Ayris Teknoloji" className="w-full pl-14 pr-6 py-4 bg-gray-50 border-2 border-transparent focus:border-blue-500 focus:bg-white rounded-[24px] outline-none transition-all font-bold text-gray-900 placeholder:text-gray-300" />
{[ { id: 'stripe', name: 'Stripe' }, { id: 'cryptomus', name: 'Cryptomus' }, { id: 'nuvei', name: 'Nuvei' }, { id: 'paykings', name: 'PayKings' }, { id: 'securionpay', name: 'SecurionPay' }, ].map((p) => ( ))}
setEditingMerchant({ ...editingMerchant, webhook_url: e.target.value })} placeholder="https://siteniz.com/webhook" className="w-full pl-14 pr-6 py-4 bg-gray-50 border-2 border-transparent focus:border-blue-500 focus:bg-white rounded-[24px] outline-none transition-all font-bold text-gray-900 placeholder:text-gray-300" />

Ödeme başarılı olduğunda bu adrese bildirim gönderilecektir.

)}
); }