Skip to content

Yapılan Ödeme İşlemi Sonrası İade/İptal ​

2D/3D kullanılarak ödeme başarıyla tamamlandıktan sonra yapılan işlemin iade/iptal edilebilmesi için bu API kullanılır.

İstek Bilgileri ​

  • Metot: POST
  • URL: https://staging.halkode.com.tr/ccpayment/api/refund
  • CANLI URL: https://app.halkode.com.tr/ccpayment/api/refund
  • Yetkilendirme: Bearer {token} Token Alma servisinden alınan değer

İstek Parametreleri (Body) ​

ParametreTipKoşulAçıklama
invoice_idstringZorunluSizin tarafınızdaki tekil sipariş ID.
merchant_keystringZorunluÜye işyeri anahtarınız.
amountdouble/empty stringZorunluİade edilecek tutar.
app_idstringZorunluUygulama anahtarı değeriniz.
app_secretstringZorunluUygulama parolası değeriniz.

Örnek İstek (Request) ​

json
{
    "invoice_id": "VP17744361965081111123",
    "amount": 100.00,
    "app_id": "{{app_id}}",
    "app_secret": "{{app_secret}}",
    "merchant_key": "{{merchant_key}}",
    "hash_key": "{{hash_key}}"
}

Başarılı Yanıt ​

Daha önceden başarılı bir şekilde gerçekleşen VP17744361965081111123 invoice_id bilgisine sahip işlem için iade/iptal işlemi yapıldığında aşağıdaki örnekte görüldüğü gibi başarılı bir yanıt döner.

json
{
    "status_code": 100,
    "status_description": "Refund completed successfully",
    "order_no": "VP17744362395298349",
    "invoice_id": "VP17744361965081111123",
    "ref_no": "",
    "ref_number": ""
}

Başarısız Yanıt ​

Rastgele yazılmış bir 'VP177443619650811111234' invoice_id bilgisi için işlem bulunamaz ve iade/iptal işlemi yapılmak istendiğinde aşağıdaki örnekte görüldüğü gibi başarısız bir yanıt döner.

json
{
    "status_code": 31,
    "status_description": "İşlem Bulunamadı",
    "order_no": "",
    "invoice_id": "VP177443619650811111234",
    "ref_no": "",
    "ref_number": ""
}

Kod Örnekleri ​

PHP Örnek Kodu
PHP

<?php

if (isset($_POST['process_payment'])) {
    // Temel değişkenleri tanımla
    $baseUrl = "https://staging.halkode.com.tr/ccpayment/api/refund";
    include 'degisken.php';
    $invoice_id = $_POST['invoice_id'];
    $amount = $_POST['amount'];
    // Token isteği
    $tokenResponse = getToken($app_id, $appSecret);
    $decodedTokenResponse = json_decode($tokenResponse, true);
    if ($decodedTokenResponse['status_code'] == 100) {
        $token = $decodedTokenResponse['data']['token'];
    } else {
        echo "<p><strong>Hata:</strong> Token alınamadı. Lütfen bilgilerinizi kontrol ediniz.</p>";
        return;
    }
    // Formdan verileri topla
    $data = array(
        "invoice_id" => $invoice_id,
        "merchant_key" => $merchantKey,
        "amount" => $amount,
    );
    // Gönderilen verileri tablodaki formatta göster
    echo "<h3>Gönderilen Veriler</h3>";
    echo "<table class='table table-bordered'>
            <thead>
                <tr>
                    <th>Fatura ID</th>
                    <th>İade Tutarı</th>
                    <th>Merchant Key</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>" . htmlspecialchars($invoice_id) . "</td>
                    <td>" . htmlspecialchars($amount) . " TL</td>
                    <td>" . htmlspecialchars($merchantKey) . "</td>
                </tr>
            </tbody>
          </table>";
    // Ödeme isteğini göndermek için CURL
    $ch = curl_init($baseUrl);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        "Authorization: Bearer $token"
    ));
    $jsonData = json_encode($data);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    // Yanıtı tabloya yerleştir
    echo "<h3>Yanıt</h3>";
    $decodedResponse = json_decode($response, true);
    echo "<table class='table table-bordered'>
            <thead>
                <tr>
                    <th>Durum Kodu</th>
                    <th>Durum Açıklaması</th>
                    <th>Sipariş Numarası</th>
                    <th>Fatura ID</th>
                    <th>Referans No</th>
                    <th>Referans Numarası</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>" . htmlspecialchars($decodedResponse['status_code']) . "</td>
                    <td>" . htmlspecialchars($decodedResponse['status_description']) . "</td>
                    <td>" . htmlspecialchars($decodedResponse['order_no']) . "</td>
                    <td>" . htmlspecialchars($decodedResponse['invoice_id']) . "</td>
                    <td>" . htmlspecialchars($decodedResponse['ref_no']) . "</td>
                    <td>" . htmlspecialchars($decodedResponse['ref_number']) . "</td>
                </tr>
            </tbody>
          </table>";
}
?>
C# /.NET Örnek Kodu
C#

using System.Text;
using System.Text.Json;
using System.Net.Http.Headers;

public class RefundController : Controller
{
    private const string URL = "api/refund";
    private readonly HttpClient _httpClient;
    private readonly ApiSettings _apiSettings;
    public RefundController()
    {
        _httpClient = new HttpClient();
        _apiSettings = new ApiSettingConfiguration().Configuration();
    }
    public IActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public async Task<IActionResult> ProcessPayment(double amount,string invoice_id)
    {
        if (amount <= 0)
        {
            ModelState.AddModelError("total", "The total must be greater than 0.");
            return View("Index");
        }

        var refundRequest = CreateRequestParameter(_apiSettings, amount, invoice_id);
        var response = await GetAsync(refundRequest);
        ViewBag.RequestData = refundRequest;
        ViewBag.ResponseData = response;
        return View("Index");
    }
    private async Task<RefundResponse> GetAsync(RefundRequest refundRequest)
    {
        var tokenResponse = await new TokenController().GetAsync();
        var jsonRequest = JsonSerializer.Serialize(refundRequest);
        var httpContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
        _httpClient.DefaultRequestHeaders.Authorization =
            new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokenResponse?.data?.token);
        try
        {
            var httpResponse = await _httpClient.PostAsync($"{_apiSettings.BaseAddress}{URL}", httpContent);
            var jsonResponse = await httpResponse.Content.ReadAsStringAsync();
            return JsonSerializer.Deserialize<RefundResponse>(jsonResponse);
        }
        catch (Exception ex)
        {
            throw new Exception($"Hata: {ex.Message}");
        }
    }
    private RefundRequest CreateRequestParameter(ApiSettings apiSettings, double amount ,string invoice_id)
    {
        var refundRequest = new RefundRequest
        {
            amount= amount,
            invoice_id = invoice_id,
            merchant_key = apiSettings.MerchantKey,
      
        };
        return refundRequest;
    }
}
JavaScript / NodeJs Örnek Kodu
JavaScript

async function checkInvoiceStatus(invoiceId, merchantKey, amount) {
    const apiUrl = "https://staging.halkode.com.tr/ccpayment/api/refund";

    // 1. REQUEST (İstek Verisi) Hazırlama
    const requestData = {
        invoice_id: invoiceId,
        merchant_key: merchantKey,
        amount: amount
    };

    try {
        // 2. REQUEST Gönderimi
        const response = await fetch(apiUrl, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                // Gerekiyorsa: 'Authorization': 'Bearer YOUR_TOKEN'
            },
            body: JSON.stringify(requestData)
        });

        // 3. RESPONSE (Yanıt) Karşılama
        if (!response.ok) {
            throw new Error(`Sunucu Hatası: ${response.status}`);
        }

        const responseData = await response.json();
        
        console.log("📥 Yanıt Alındı:", responseData);

        // Yanıt içeriğine göre işlem yapma
        if (responseData.status_code === 100) {
            console.log("İşlem Başarılı:", responseData.message);
        } else {
            console.warn("İşlem Başarısız:", responseData.status_description);
        }

        return responseData;

    } catch (error) {
        console.error("Hata Oluştu:", error.message);
    }
}