Refactor: Fully migrated to direct PostgreSQL, implemented Public API v1, fixed Vercel deployment conflicts, and updated documentation

This commit is contained in:
mstfyldz
2026-03-12 21:54:57 +03:00
parent 321f25a15c
commit 515d513c1f
29 changed files with 1002 additions and 675 deletions

View File

@@ -1,34 +1,28 @@
import React from 'react';
import { supabaseAdmin } from '@/lib/supabase-admin';
import { db } from '@/lib/db';
import {
Terminal,
Copy,
Check,
Globe,
Webhook,
Zap,
ShieldCheck,
Code2
Code2,
Server,
Link as LinkIcon
} from 'lucide-react';
import Link from 'next/link';
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';
async function getMerchant(identifier: string) {
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(identifier);
const query = supabaseAdmin
.from('merchants')
.select('*');
const queryText = isUUID
? 'SELECT * FROM merchants WHERE id = $1 LIMIT 1'
: 'SELECT * FROM merchants WHERE short_id = $1 LIMIT 1';
if (isUUID) {
query.eq('id', identifier);
} else {
query.eq('short_id', identifier);
}
const { data, error } = await query.single();
return data;
const result = await db.query(queryText, [identifier]);
return result.rows[0];
}
export default async function MerchantIntegrationPage(props: {
@@ -45,112 +39,147 @@ export default async function MerchantIntegrationPage(props: {
redirect(`/merchant/${identifier}/login`);
}
const checkoutUrl = `https://p2cgateway.com/checkout?merchant_id=${merchant.short_id || merchant.id}&amount=100&currency=TRY&ref_id=SİPARİŞ_123&callback_url=https://siteniz.com/basarili`;
const host = process.env.NEXT_PUBLIC_BASE_URL || 'https://p2cgateway.com';
const checkoutUrl = `${host}/checkout?merchant_id=${merchant.short_id || merchant.id}&amount=100&currency=TRY&ref_id=SİPARİŞ_123`;
return (
<div className="max-w-5xl space-y-12 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-20">
<div className="max-w-6xl space-y-16 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32">
{/* Header */}
<div>
<h1 className="text-3xl font-black text-gray-900 tracking-tight">Teknik Entegrasyon</h1>
<p className="text-xs text-gray-400 font-bold uppercase tracking-widest mt-2 px-1">Ödeme sistemini sitenize nasıl bağlarsınız?</p>
<div className="flex flex-col md:flex-row md:items-end justify-between gap-6">
<div>
<h1 className="text-4xl font-black text-gray-900 tracking-tight">Entegrasyon Rehberi</h1>
<p className="text-xs text-gray-400 font-black uppercase tracking-[0.3em] mt-3 px-1 border-l-4 border-blue-600 pl-4">Ödeme sistemini sisteminize dahil edin</p>
</div>
</div>
{/* Quick Start Card */}
<div className="bg-gray-900 rounded-[40px] p-12 text-white relative overflow-hidden shadow-2xl">
<div className="relative z-10 grid grid-cols-1 lg:grid-cols-2 gap-12 items-center">
<div className="space-y-6">
<div className="flex items-center gap-4">
<div className="w-12 h-12 bg-blue-600 rounded-2xl flex items-center justify-center">
<Zap size={24} />
</div>
<h2 className="text-2xl font-black">Hızlı Ödeme Linki</h2>
{/* Methods Selection */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-10">
{/* Option 1: Quick Link */}
<div className="bg-white p-12 rounded-[48px] border border-gray-100 shadow-xl shadow-gray-100/50 space-y-10 relative overflow-hidden group">
<div className="absolute top-0 right-0 w-32 h-32 bg-blue-50 rounded-full -mr-16 -mt-16 group-hover:scale-150 transition-transform duration-700"></div>
<div className="space-y-6 relative">
<div className="w-16 h-16 bg-blue-600 rounded-3xl flex items-center justify-center text-white shadow-lg shadow-blue-200">
<LinkIcon size={32} />
</div>
<p className="text-gray-400 text-lg leading-relaxed font-medium">
Entegrasyonun en basit yolu, müşterilerinizi aşağıdaki URL yapısını kullanarak ödeme sayfasına yönlendirmektir.
<h2 className="text-2xl font-black text-gray-900">1. Hızlı Ödeme Linki</h2>
<p className="text-gray-500 font-medium leading-relaxed">
Kod yazmanıza gerek kalmadan, müşterilerinizi doğrudan ödeme sayfamıza yönlendirebilirsiniz. Parametreleri URL üzerinden iletebilirsiniz.
</p>
</div>
<div className="bg-white/5 p-6 rounded-3xl border border-white/10 space-y-4">
<p className="text-[10px] font-black text-gray-500 uppercase tracking-widest">Sizin Hazır Linkiniz</p>
<div className="bg-black p-4 rounded-xl border border-white/5 font-mono text-[10px] text-blue-400 break-all leading-relaxed">
<div className="space-y-4">
<p className="text-[10px] font-black text-gray-400 uppercase tracking-widest pl-1">Örnek Yapı</p>
<div className="bg-gray-50 p-6 rounded-3xl border border-gray-100 font-mono text-[11px] text-gray-600 break-all leading-relaxed relative group/code">
{checkoutUrl}
<button className="absolute top-4 right-4 p-2 bg-white rounded-lg shadow-sm opacity-0 group-hover/code:opacity-100 transition-opacity">
<Copy size={14} className="text-gray-400" />
</button>
</div>
</div>
</div>
{/* Option 2: Server-to-Server API */}
<div className="bg-gray-900 p-12 rounded-[48px] shadow-2xl space-y-10 relative overflow-hidden group">
<div className="absolute top-0 right-0 w-32 h-32 bg-white/5 rounded-full -mr-16 -mt-16"></div>
<div className="space-y-6 relative">
<div className="w-16 h-16 bg-emerald-500 rounded-3xl flex items-center justify-center text-white shadow-lg shadow-emerald-900/20">
<Server size={32} />
</div>
<h2 className="text-2xl font-black text-white">2. Profesyonel API (v1)</h2>
<p className="text-gray-400 font-medium leading-relaxed">
Sunucu taraflı entegrasyon ile daha güvenli işlemler başlatın. Fiyat manipülasyonunu engeller ve sessiz oturumlar oluşturur.
</p>
</div>
<div className="space-y-4">
<p className="text-[10px] font-black text-gray-500 uppercase tracking-widest pl-1">Endpoint</p>
<div className="bg-white/5 p-6 rounded-3xl border border-white/10 font-mono text-[11px] text-emerald-400">
POST {host}/api/v1/checkout
</div>
</div>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
{/* Credentials */}
<div className="bg-white p-10 rounded-[40px] border border-gray-100 shadow-sm space-y-8">
<div className="flex items-center gap-4">
<div className="w-12 h-12 bg-blue-50 rounded-2xl flex items-center justify-center text-blue-600">
<ShieldCheck size={24} />
</div>
<h3 className="text-xl font-black text-gray-900">Kimlik Bilgileri</h3>
{/* API Details Section */}
<div className="bg-white p-12 rounded-[48px] border border-gray-100 shadow-sm space-y-12">
<div className="flex items-center gap-6">
<div className="w-14 h-14 bg-gray-50 rounded-2xl flex items-center justify-center text-gray-900">
<ShieldCheck size={28} />
</div>
<div className="space-y-6">
<div className="p-6 bg-gray-50 rounded-3xl border border-gray-100 space-y-3">
<label className="text-[10px] font-black text-gray-400 uppercase tracking-widest pl-1">Merchant ID (Firma Kimliği)</label>
<div className="flex items-center justify-between gap-3 bg-white p-4 rounded-xl border border-gray-200">
<code className="text-xs font-mono font-bold text-gray-600 truncate">{merchant.id}</code>
<Copy size={14} className="text-gray-300 cursor-pointer" />
</div>
</div>
<div className="p-6 bg-gray-50 rounded-3xl border border-gray-100 space-y-3">
<label className="text-[10px] font-black text-gray-400 uppercase tracking-widest pl-1">API Secret Key</label>
<div className="flex items-center justify-between gap-3 bg-white p-4 rounded-xl border border-gray-200">
<code className="text-xs font-mono font-bold text-gray-600"></code>
<button className="text-[10px] font-black text-blue-600 uppercase">Göster</button>
</div>
</div>
<div>
<h3 className="text-2xl font-black text-gray-900">API Erişimi ve Güvenlik</h3>
<p className="text-xs text-gray-400 font-bold uppercase tracking-widest mt-1">İsteklerinizi doğrulamak için bu anahtarları kullanın</p>
</div>
</div>
{/* Webhooks */}
<div className="bg-white p-10 rounded-[40px] border border-gray-100 shadow-sm space-y-8">
<div className="flex items-center gap-4">
<div className="w-12 h-12 bg-purple-50 rounded-2xl flex items-center justify-center text-purple-600">
<Webhook size={24} />
<div className="grid grid-cols-1 md:grid-cols-2 gap-10">
<div className="space-y-4">
<label className="text-[10px] font-black text-gray-400 uppercase tracking-widest ml-2">Merchant ID</label>
<div className="bg-gray-50 p-5 rounded-2xl border border-gray-100 flex items-center justify-between">
<code className="text-xs font-mono font-bold text-gray-600">{merchant.id}</code>
<Copy size={16} className="text-gray-300 cursor-pointer hover:text-blue-600 transition" />
</div>
<h3 className="text-xl font-black text-gray-900">Webhook Yapılandırması</h3>
</div>
<p className="text-sm text-gray-500 font-medium leading-relaxed">
Ödeme başarılı olduğunda sistemimiz belirtilen adrese bir POST isteği gönderir.
<div className="space-y-4">
<label className="text-[10px] font-black text-gray-400 uppercase tracking-widest ml-2">API Secret Key</label>
<div className="bg-gray-50 p-5 rounded-2xl border border-gray-100 flex items-center justify-between">
<code className="text-xs font-mono font-bold text-gray-600">
{merchant.api_key.substring(0, 8)}
</code>
<button className="text-[10px] font-black text-blue-600 uppercase tracking-widest hover:underline">Anahtarı Göster</button>
</div>
</div>
</div>
</div>
{/* Webhook Settings */}
<div className="bg-white p-12 rounded-[48px] border border-gray-100 shadow-sm space-y-12">
<div className="flex items-center gap-6">
<div className="w-14 h-14 bg-purple-50 rounded-2xl flex items-center justify-center text-purple-600">
<Webhook size={28} />
</div>
<div>
<h3 className="text-2xl font-black text-gray-900">Olay Bildirimleri (Webhooks)</h3>
<p className="text-xs text-gray-400 font-bold uppercase tracking-widest mt-1">Ödeme sonuçlarını anlık olarak sunucunuzda karşılayın</p>
</div>
</div>
<div className="space-y-8">
<p className="text-gray-500 font-medium leading-relaxed max-w-2xl">
İşlem tamamlandığında sistemimiz belirttiğiniz URL'ye <code className="bg-gray-100 px-2 py-1 rounded text-blue-600 font-bold">POST</code> isteği gönderir. Bu isteğin içerisinde işlemin tüm detayları yer alır.
</p>
<div className="p-6 bg-gray-50 rounded-3xl border border-gray-100 space-y-4">
<div className="p-8 bg-gray-50 rounded-[32px] border border-gray-100 space-y-6">
<div className="flex items-center justify-between">
<span className="text-[10px] font-black text-gray-400 uppercase tracking-widest">Mevcut Webhook URL</span>
<span className={`text-[10px] font-black px-2 py-0.5 rounded-md ${merchant.webhook_url ? 'bg-emerald-50 text-emerald-600' : 'bg-red-50 text-red-600'}`}>
{merchant.webhook_url ? 'AKTİF' : 'AYARLANMAMIŞ'}
<span className="text-[11px] font-black text-gray-400 uppercase tracking-widest ml-2">Webhook URL</span>
<span className={`text-[10px] font-black px-3 py-1 rounded-full ${merchant.webhook_url ? 'bg-emerald-100 text-emerald-700' : 'bg-red-100 text-red-700'}`}>
{merchant.webhook_url ? 'HİZMETE HAZIR' : 'HENÜZ TANIMLANMAMIŞ'}
</span>
</div>
<div className="bg-white p-4 rounded-xl border border-gray-200">
<code className="text-xs font-bold text-gray-600 truncate block">
{merchant.webhook_url || 'https://henuz-bir-adres-tanimlanmadi.com'}
<div className="bg-white p-6 rounded-2xl border border-gray-200">
<code className="text-sm font-bold text-gray-700 break-all">
{merchant.webhook_url || 'https://siteniz.com/api/payment-callback'}
</code>
</div>
<p className="text-[10px] text-gray-400 font-bold uppercase text-center mt-2 leading-relaxed">
Webook URL adresinizi değiştirmek için <br /> destek ekibi ile iletişime geçin.
</p>
</div>
</div>
</div>
{/* Resources */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
{/* Footer Resources */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-8">
{[
{ title: 'API Referansı', icon: Code2, color: 'blue' },
{ title: 'Hazır Kütüphaneler', icon: Terminal, color: 'emerald' },
{ title: 'Teknik Destek', icon: Globe, color: 'purple' },
{ title: 'Postman Koleksiyonu', icon: Terminal, color: 'blue' },
{ title: 'Geliştirici Dokümanları', icon: Code2, color: 'emerald' },
{ title: 'Teknik Yardım', icon: Globe, color: 'gray' },
].map((r) => (
<div key={r.title} className="bg-white p-8 rounded-[32px] border border-gray-100 shadow-sm flex items-center gap-6 hover:border-gray-300 transition-colors cursor-pointer group">
<div className={`w-12 h-12 bg-${r.color}-50 rounded-2xl flex items-center justify-center text-${r.color}-600 group-hover:bg-${r.color}-600 group-hover:text-white transition-all`}>
<r.icon size={22} />
<div key={r.title} className="bg-white p-8 rounded-[32px] border border-gray-100 shadow-sm flex items-center gap-6 hover:shadow-lg transition-all cursor-pointer group hover:-translate-y-1">
<div className={`w-14 h-14 bg-gray-50 rounded-2xl flex items-center justify-center text-gray-400 group-hover:bg-blue-600 group-hover:text-white transition-all`}>
<r.icon size={24} />
</div>
<span className="text-sm font-black text-gray-900 leading-tight">{r.title}</span>
<span className="text-sm font-black text-gray-900 uppercase tracking-tight">{r.title}</span>
</div>
))}
</div>

View File

@@ -8,7 +8,7 @@ import {
ShieldCheck
} from 'lucide-react';
import MerchantSidebar from '@/components/merchant/MerchantSidebar';
import { supabaseAdmin } from '@/lib/supabase-admin';
import { db } from '@/lib/db';
export default async function MerchantLayout({
children,
@@ -26,11 +26,8 @@ export default async function MerchantLayout({
let resolvedId = identifier;
if (!isUUID) {
const { data: merchant } = await supabaseAdmin
.from('merchants')
.select('id')
.eq('short_id', identifier)
.single();
const result = await db.query('SELECT id FROM merchants WHERE short_id = $1 LIMIT 1', [identifier]);
const merchant = result.rows[0];
if (merchant) {
resolvedId = merchant.id;
}

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { supabaseAdmin } from '@/lib/supabase-admin';
import { db } from '@/lib/db';
import {
TrendingUp,
TrendingDown,
@@ -21,30 +21,23 @@ async function getMerchantData(identifier: string) {
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(identifier);
// Fetch merchant details
const query = supabaseAdmin
.from('merchants')
.select('*');
const mQueryText = isUUID
? 'SELECT * FROM merchants WHERE id = $1 LIMIT 1'
: 'SELECT * FROM merchants WHERE short_id = $1 LIMIT 1';
const mResult = await db.query(mQueryText, [identifier]);
const merchant = mResult.rows[0];
if (isUUID) {
query.eq('id', identifier);
} else {
query.eq('short_id', identifier);
}
const { data: merchant, error: mError } = await query.single();
if (mError || !merchant) return null;
if (!merchant) return null;
const id = merchant.id; // Always use UUID for internal lookups
// Fetch merchant transactions
const { data: transactions, error: tError } = await supabaseAdmin
.from('transactions')
.select('*')
.eq('merchant_id', id)
.order('created_at', { ascending: false });
if (tError) return null;
const tResult = await db.query(
'SELECT * FROM transactions WHERE merchant_id = $1 ORDER BY created_at DESC',
[id]
);
const transactions = tResult.rows;
const successfulTransactions = transactions.filter(t => t.status === 'succeeded');
const totalRevenue = successfulTransactions.reduce((acc, t) => acc + Number(t.amount), 0);

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { supabaseAdmin } from '@/lib/supabase-admin';
import { db } from '@/lib/db';
import { format } from 'date-fns';
import { tr } from 'date-fns/locale';
import {
@@ -16,27 +16,20 @@ import { redirect } from 'next/navigation';
async function getMerchantTransactions(identifier: string) {
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(identifier);
const query = supabaseAdmin
.from('merchants')
.select('id')
const mQueryText = isUUID
? 'SELECT id FROM merchants WHERE id = $1 LIMIT 1'
: 'SELECT id FROM merchants WHERE short_id = $1 LIMIT 1';
if (isUUID) {
query.eq('id', identifier);
} else {
query.eq('short_id', identifier);
}
const { data: merchant } = await query.single();
const mResult = await db.query(mQueryText, [identifier]);
const merchant = mResult.rows[0];
if (!merchant) return null;
const { data, error } = await supabaseAdmin
.from('transactions')
.select('*')
.eq('merchant_id', merchant.id)
.order('created_at', { ascending: false });
const tResult = await db.query(
'SELECT * FROM transactions WHERE merchant_id = $1 ORDER BY created_at DESC',
[merchant.id]
);
if (error) return null;
return data;
return tResult.rows;
}
export default async function MerchantTransactionsPage(props: {
@@ -53,7 +46,8 @@ export default async function MerchantTransactionsPage(props: {
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(identifier);
let resolvedId = identifier;
if (!isUUID) {
const { data: merchant } = await supabaseAdmin.from('merchants').select('id').eq('short_id', identifier).single();
const result = await db.query('SELECT id FROM merchants WHERE short_id = $1 LIMIT 1', [identifier]);
const merchant = result.rows[0];
if (merchant) resolvedId = merchant.id;
}