Ana içeriğe geç

Yeni siparis olustur + bakiyeden OTOMATIK odeme dene

POST 

/orders

3 sonuclu akis:

  1. StockService::isAvailable(pid) = false ise 409 product_unavailable. 1b. extra.configoptions icinde bayi satisi KAPALI bir alt-secenek (orn. stogu biten lokasyon) secilmisse 409 config_option_out_of_stock (Rabisu Master mod_rabisu_master_configoption_stock.in_stock=0). Bayi modulu bunlari zaten gizler; bu sunucu tarafi ikinci savunma hattidir.
  2. period whitelist disi ise 422 invalid_period.
  3. WHMCS AddOrder -> order + unpaid invoice uretilir.
  4. Bayinin auto_apply_credit toggle'i (GET /auth/me) kontrol edilir:
    • false -> ApplyCredit ATLANIR; status=pending_payment, payment_applied=false, notice=auto_apply_credit_disabled. Bayi faturayi kendi tercihine gore (panelden/havaleden) manuel oder. Toggle admin CLI ile acilir: php bin/api-key-update.php <id> --auto-apply-credit=1.
    • true (default) -> WHMCS ApplyCredit (TEK cagri) sonuca gore:
      • success -> status=pending_provision, payment_applied=true; WHMCS InvoicePaid hook'u virtualizor queue cron'unu tetikler.
      • insufficient funds -> status=pending_payment, notice=insufficient_credit; bayi manuel odeyebilir.
      • HTTP 5xx / timeout -> status=payment_failed, RequestLogger'a alarm flag'i ile kayit acilir.

ÇAĞRILMAYAN aksiyonlar: AcceptOrder (WHMCS InvoicePaid hook zaten devreye girer), VirtualizorClient (WHMCS cron VPS'i kurar), bakiye pre-check, DeleteOrder (insufficient edge case'inde bile).

Idempotency-Key header ZORUNLUDUR (aksi halde 400 missing_idempotency_key). Ayni key+body replay icin 202 cached response doner.

Request

Responses

Siparis DB'ye yazildi. status ApplyCredit sonucunu yansitir; bayi VPS'in kurulmasini GET /orders/{id} ile polla.

Response Headers
    X-Idempotent-Replay

    Cache'den donen tekrarli istekte "true" olur.