Charges — Direkt Ödeme

Sanal POS gibi kullan: backend'in bir sipariş için charge oluşturur, dönen url'e müşteriyi yönlendirir, ödeme bitince webhook senin reference'ınla geri döner. Tek seferlik ödeme ve abonelik için aynı uçtan.

Kart girişi PCI gereği bizim hosted ödeme sayfamızdaolur (Stripe/iyzico dahil tüm gateway'ler böyle). Akış: charge oluştur → url'e yönlendir → ödeme → webhook.

Charge oluştur

POST/api/v1/charges
amount         integer  (zorunlu)  Tutar, minor units (14990 = $149.90)
description    string   (ops.)     Ödeme açıklaması
currency       string   (ops.)     Varsayılan: platform para birimi
reference      string   (ops.)     SENİN sipariş no'n — webhook & redirect'te döner
customer_email string   (ops.)
success_url    string   (ops.)     Başarılı ödeme sonrası dönülecek URL
cancel_url     string   (ops.)     İptal/başarısız sonrası dönülecek URL
type           string   (ops.)     "one_time" (varsayılan) | "subscription"
interval       string   (ops.)     subscription için "month" | "year"
curl -X POST http://localhost:3000/api/v1/charges \
  -H "Authorization: Bearer mm_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 14990,
    "description": "Sipariş #1234",
    "reference": "1234",
    "success_url": "https://siteniz.com/odeme/basarili",
    "cancel_url":  "https://siteniz.com/odeme/iptal"
  }'

Yanıt (201):

{
  "id": "clx...",
  "object": "charge",
  "url": "http://localhost:3000/pay/a1b2c3...",
  "amount": 14990,
  "currency": "usd",
  "reference": "1234",
  "type": "one_time",
  "status": "pending"
}

Müşteriyi dönen url'e yönlendir. Tek seferlik charge ödendikten sonra link otomatik kapanır.

Ödeme bitince

İki şey olur: (1) müşteri success_url'ine ?status=success&reference=1234&payment_intent=pi_… ile döner, (2) webhook'una imzalı payment.succeeded gider — reference ile siparişi eşle:

{
  "type": "payment.succeeded",
  "data": {
    "id": "clx...",
    "amount": 14990,
    "currency": "usd",
    "net": 14241,
    "customer_email": "ornek@email.com",
    "reference": "1234",
    "subscription": null
  }
}
Siparişi webhook'la onayla (redirect sahte olabilir). İmza doğrulaması için Webhooks.

Durum sorgula

GET/api/v1/charges?id=<id>
curl "http://localhost:3000/api/v1/charges?id=clx..." \
  -H "Authorization: Bearer mm_live_xxx"
# → { ..., "status": "paid", "paid_at": 1750000000 }