recurr.
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.

lib/adapter.ts
import { MyAdapter } from './my-adapter' // kendi adapter'ınız

export const adapter = new MyAdapter()

2. Core Nesnelerini Başlat

lib/recurr.ts
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

app/api/billing/[...bp]/route.ts
import { billingApp } from '@/lib/recurr'

export const { GET, POST } = billingApp

4. Billing Portal UI'ını Ekle

app/billing/[[...billing]]/page.tsx
import { billingApp } from '@/lib/recurr'

export default billingApp.page

CSS'i layout'unuza ekleyin:

app/layout.tsx
import '@vinenastudio/recurr-nextjs/ui/styles.css'

5. Vercel Cron'u Yapılandır

vercel.json
{
  "crons": [{
    "path": "/api/billing/cron",
    "schedule": "0 8,14,20 * * *"
  }]
}

Hazır!

Artık şu sayfalar çalışıyor:

SayfaAçıklama
/billing/choose-planPlan seçimi
/billing/checkoutKart formu (doğrudan PayTR'ye gider)
/billing/successÖdeme sonrası onay
/billing/portalAbonelik durumu ve iptal
/billing/managementYönetim paneli

On this page