Getting Started
Hızlı Başlangıç
Next.js uygulamanıza 5 adımda abonelik sistemi ekleyin
1. Adapter'ı Oluştur
Kendi veritabanınız için BetterPurchaseAdapter arayüzünü uygulayan bir sınıf yazın.
Detaylı açıklama için Adapter Pattern sayfasına bakın.
import { MyAdapter } from './my-adapter' // kendi adapter'ınız
export const adapter = new MyAdapter()2. Core Nesnelerini Başlat
import { PayTRClient, SubscriptionManager } from '@vinenastudio/recurr'
import { Management, createBillingApp } from '@vinenastudio/recurr-nextjs'
import { adapter } from './adapter'
export const management = new Management({
username: process.env.ADMIN_USER!,
password: process.env.ADMIN_PASS!,
})
export const paytrClient = new PayTRClient({
merchantId: process.env.PAYTR_MERCHANT_ID!,
merchantKey: process.env.PAYTR_MERCHANT_KEY!,
merchantSalt: process.env.PAYTR_MERCHANT_SALT!,
})
export const subscriptionManager = new SubscriptionManager(
paytrClient,
adapter,
{
appUrl: process.env.NEXT_PUBLIC_APP_URL!,
onPaymentFailed: async (subscriber, attempt, max) => {},
onSubscriptionCancelled: async (subscriber) => {},
}
)
export const billingApp = createBillingApp({
client: paytrClient,
adapter,
subscriptionManager,
management,
secret: process.env.CRON_SECRET!,
appUrl: process.env.NEXT_PUBLIC_APP_URL!,
successPath: '/billing/success',
onPaymentSuccess: async ({ subscriber, payment }) => {
console.log(`Ödeme başarılı: ${subscriber.email}`)
},
onPaymentFailure: async ({ subscriber, reason }) => {
console.log(`Ödeme başarısız: ${subscriber?.email} — ${reason}`)
},
})3. API Route Handler'ı Ekle
import { billingApp } from '@/lib/recurr'
export const { GET, POST } = billingApp4. Billing Portal UI'ını Ekle
import { billingApp } from '@/lib/recurr'
export default billingApp.pageCSS'i layout'unuza ekleyin:
import '@vinenastudio/recurr-nextjs/ui/styles.css'5. Vercel Cron'u Yapılandır
{
"crons": [{
"path": "/api/billing/cron",
"schedule": "0 8,14,20 * * *"
}]
}Hazır!
Artık şu sayfalar çalışıyor:
| Sayfa | Açıklama |
|---|---|
/billing/choose-plan | Plan seçimi |
/billing/checkout | Kart formu (doğrudan PayTR'ye gider) |
/billing/success | Ödeme sonrası onay |
/billing/portal | Abonelik durumu ve iptal |
/billing/management | Yönetim paneli |