Ön Provizyonlu İşlem Sonrası Ödeme Doğrulama
Ön Provizyonlu Ödeme sonrası yapılan işlem sistemde 'Beklemede' olarak oluşturulur. Beklemede olan bu işlemi Başarısız veya Tamamlanmış hale getirmek gereklidir. Bunun için aşağıdaki istek parametreleri kullanılarak bu API çağrılmalıdır.
İstek Bilgileri
- Metot:
POST - URL:
https://staging.halkode.com.tr/ccpayment/api/confirmPayment - CANLI URL:
https://app.halkode.com.tr/ccpayment/api/confirmPayment - Yetkilendirme:
Bearer {token}Token Alma servisinden alınan değer
İstek Parametreleri (Body)
| Parametre | Tip | Koşul | Açıklama |
|---|---|---|---|
invoice_id | string | Zorunlu | Sizin tarafınızdaki tekil sipariş ID. |
merchant_key | string | Zorunlu | Üye işyeri anahtarınız. |
status | int | Zorunlu | Eğer bu değer 1 ise işlem onaylanır, 2 ise iptal edilir. |
hash_key | string | Zorunlu | Güvenlik imzası. |
total | double | Opsiyonel | Toplam tutar. |
Örnek İstek (Request)
json
{
"total":"205.00",
"invoice_id":"33491162435928",
"status":"1",
"merchant_key":"{{merchant_key}}",
"hash_key":"{{hash_key}}"
}Başarılı Yanıt
json
{
"status_code": 100,
"status_description": "An order has been taken place for this invoice id: 33491162435928",
"transaction_status": "Completed",
"order_id": "162435932934307",
"invoice_id": "33491162435928"
}Başarısız Yanıt
json
{
"status_code": 105,
"status_description": " The transaction is not Approved",
"transaction_status": "Pending",
"order_id": "162435924998223",
"invoice_id": "50781624359247"
}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/confirmPayment";
include 'degisken.php';
// 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 al
$invoice_id = $_POST['invoice_id'];
$total = $_POST['total'];
$status = "1"; // Sabit status değeri
// Hash hesaplaması yapıyoruz
$hash_key = generateConfrimPaymentHashKey($merchantKey, $invoice_id, $status, $appSecret);
// Gönderilen verileri hazırlama
$data = array(
"merchant_key" => $merchantKey,
"invoice_id" => $invoice_id,
"total" => $total,
"status" => $status,
"hash_key" => $hash_key
);
// Ö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ı işlem sonrasında gösterilecek
$responseData = json_decode($response, true);
}
?>C# /.NET Örnek Kodu
C#
using System.Text;
using System.Text.Json;
using System.Net.Http.Headers;
public class ConfirmPaymentController : Controller
{
private const string URL = "api/confirmPayment";
private readonly HttpClient _httpClient;
private readonly ApiSettings _apiSettings;
public ConfirmPaymentController()
{
_httpClient = new HttpClient();
_apiSettings = new ApiSettingConfiguration().Configuration();
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<IActionResult> ProcessPayment(string invoice_id, double total, string status)
{
if (total <= 0)
{
ModelState.AddModelError("total", "The total must be greater than 0.");
return View("Index");
}
var confirmPaymentRequest = CreateRequestParameter(_apiSettings, invoice_id, total, status);
var response = await GetAsync(confirmPaymentRequest);
ViewBag.RequestData = confirmPaymentRequest;
ViewBag.ResponseData = response;
return View("Index");
}
private async Task<ConfirmPaymentResponse> GetAsync(ConfirmPaymentRequest confirmPaymentRequest)
{
var tokenResponse = await new TokenController().GetAsync();
var jsonRequest = JsonSerializer.Serialize(confirmPaymentRequest);
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<ConfirmPaymentResponse>(jsonResponse);
}
catch (Exception ex)
{
throw new Exception($"Hata: {ex.Message}");
}
}
private ConfirmPaymentRequest CreateRequestParameter(ApiSettings apiSettings, string invoice_id, double total, string status)
{
var confirmPaymentRequest = new ConfirmPaymentRequest
{
total = total,
invoice_id = invoice_id,
status="1",
merchant_key = apiSettings.MerchantKey,
};
HashGenerator hashGenerator = new();
confirmPaymentRequest.hash_key = hashGenerator.GenerateHashKey(
false,
confirmPaymentRequest.merchant_key,
confirmPaymentRequest.invoice_id,
confirmPaymentRequest.status);
return confirmPaymentRequest;
}
}JavaScript / NodeJs Örnek Kodu
JavaScript
async function sendPaymentData(merchantKey, invoiceId, total, status, hashKey) {
const url = "https://staging.halkode.com.tr/ccpayment/api/confirmPayment";
const data = {
merchant_key: merchantKey,
invoice_id: invoiceId,
total: total,
status: status,
hash_key: hashKey
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
});
const result = await response.json();
console.log("Sunucu Yanıtı:", result);
return result;
} catch (error) {
console.error("İstek sırasında hata oluştu:", error);
}
}
