Test Form



<!doctype html>
<html>
<head>
<title>Sanal POS entegrasyonu örnek PHP sayfamız</title>
<meta charset="utf-8">
</head>
<body>

<?php
// sx değeriniz size verilecektir
$sx="114488219|SjEH1wb6qoqWtN2X9/5Y6sVy/JxniIbR01EKWRcHxPl0iAjkadGNaNAEV5l6O3tjzcPEiFOO8OwCSb6dzo/fN/2zyv7sVbweqJvgKr7cWnMwPIgqipXBk+B7Z4bFqmeD1LlUgNMXdstufUNxmCHIfb3nT0NDrfScCxlQX8H1YYPvcNE+oTtci3fB+X/fpYec0Gu2JPAIzG74pQN07MmdHq+GSR73+RkAjMi0cP4pfjNf6C/0Igc6qcnTtYH9YIJIpRxySQ==";
$merchantSecretKey="_YXMmaRPOK05Gzztl9lds"; // size özel
$successUrl="https://nkolaydepo.com/success-yeni-kk-provizyon-depo-prod-yeni";
$failUrl="https://nkolaydepo.com/fail";
$amount="1.00";
$clientRefCode="2352345";
$use3D="true";
$rnd = date("d.m.Y H:i:s");
$agentCode="1236";
$detail="false";
$transactionType="sales";
$customerKey = "";
$hashstr = $sx . "|" . $clientRefCode . "|" . $amount . "|" . $successUrl . "|" . $failUrl . "|" . $rnd . "|" . $customerKey . "|" . $merchantSecretKey;

$hash = mb_convert_encoding($hashstr, 'UTF-8');
$hashedBytes = hash("sha512", $hash, true);
$hashDataV2 = base64_encode($hashedBytes);
?>

<form method="post" action="https://paynkolaytest.nkolayislem.com.tr/Vpos">
  <input type="hidden" name="sx" value="<?= $sx ?>">
  <input type="hidden" name="successUrl" value="<?= $successUrl ?>">
  <input type="hidden" name="failUrl" value="<?= $failUrl ?>">
  <input type="hidden" name="amount" value="<?= $amount ?>">
  <input type="hidden" name="clientRefCode" value="<?= $clientRefCode ?>">
  <input type="hidden" name="use3D" value="<?= $use3D ?>">
  <input type="hidden" name="rnd" value="<?= $rnd ?>">
  <input type="hidden" name="agentCode" value="<?= $agentCode ?>">
  <input type="hidden" name="transactionType" value="<?= $transactionType ?>">
  <input type="hidden" name="hashDataV2" value="<?= $hashDataV2 ?>">
  <input type="submit" value="Gönder" />
</form>

</body>
</html>

sx ve merchantSecretKey değerleri Pay N Kolay tarafından verilir. Doğru POST edilirse 3D ekranı açılır.

clientRefCode ile ihtiyacınız olan parametreleri pipe işareti (|) ile gönderebilirsiniz.

SanalPos.cshtml

@page "/sanalpos"
@model MyApi.Pages.SanalPosModel
<!doctype html>
<html lang="tr">
<head><meta charset="utf-8" /><title>Sanal POS Örnek</title></head>
<body>
  <form method="post" action="https://paynkolaytest.nkolayislem.com.tr/Vpos">
    <input type="hidden" name="sx"              value="@Model.Sx" />
    <input type="hidden" name="successUrl"      value="@Model.SuccessUrl" />
    <input type="hidden" name="failUrl"         value="@Model.FailUrl" />
    <input type="hidden" name="amount"          value="@Model.Amount" />
    <input type="hidden" name="clientRefCode"   value="@Model.ClientRefCode" />
    <input type="hidden" name="use3D"           value="@Model.Use3D" />
    <input type="hidden" name="rnd"             value="@Model.Rnd" />
    <input type="hidden" name="agentCode"       value="@Model.AgentCode" />
    <input type="hidden" name="detail"          value="@Model.Detail" />
    <input type="hidden" name="transactionType" value="@Model.TransactionType" />
    <input type="hidden" name="hashDataV2"      value="@Model.HashDataV2" />
    <button type="submit">Gönder</button>
  </form>
</body>
</html>
SanalPos.cshtml.cs

using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Security.Cryptography;
using System.Text;
using System.Globalization;

namespace MyApi.Pages
{
    public class SanalPosModel : PageModel
    {
        private readonly IConfiguration _config;
        public SanalPosModel(IConfiguration config) => _config = config;

        public string Sx { get; private set; } =
            "114488219|SjEH1wb6qoqWtN2X9/5Y6sVy/JxniIbR01EKWRcHxPl0iAjkadGNaNAEV5l6O3tjzcPEiFOO8OwCSb6dzo/fN/2zyv7sVbweqJvgKr7cWnMwPIgqipXBk+B7Z4bFqmeD1LlUgNMXdstufUNxmCHIfb3nT0NDrfScCxlQX8H1YYPvcNE+oTtci3fB+X/fpYec0Gu2JPAIzG74pQN07MmdHq+GSR73+RkAjMi0cP4pfjNf6C/0Igc6qcnTtYH9YIJIpRxySQ==";
        public string SuccessUrl { get; private set; } = "https://nkolaydepo.com/success-yeni-kk-provizyon-depo-prod-yeni";
        public string FailUrl    { get; private set; } = "https://nkolaydepo.com/fail";
        public string Amount     { get; private set; } = "1.00";
        public string ClientRefCode { get; private set; } = "2352345";
        public string Use3D      { get; private set; } = "true";
        public string AgentCode  { get; private set; } = "1236";
        public string Detail     { get; private set; } = "false";
        public string TransactionType { get; private set; } = "sales";
        public string CustomerKey { get; private set; } = "";
        public string Rnd { get; private set; } = "";
        public string HashDataV2 { get; private set; } = "";

        public void OnGet()
        {
            // optional: override from env/appsettings (safer)
            Sx              = _config["PaynKolay:Sx"] ?? Sx;
            SuccessUrl      = _config["PaynKolay:SuccessUrl"] ?? SuccessUrl;
            FailUrl         = _config["PaynKolay:FailUrl"] ?? FailUrl;
            Amount          = _config["PaynKolay:Amount"] ?? Amount;
            ClientRefCode   = _config["PaynKolay:ClientRefCode"] ?? ClientRefCode;
            Use3D           = _config["PaynKolay:Use3D"] ?? Use3D;
            AgentCode       = _config["PaynKolay:AgentCode"] ?? AgentCode;
            Detail          = _config["PaynKolay:Detail"] ?? Detail;
            TransactionType = _config["PaynKolay:TransactionType"] ?? TransactionType;
            CustomerKey     = _config["PaynKolay:CustomerKey"] ?? CustomerKey;

            var merchantSecretKey = _config["PaynKolay:MerchantSecretKey"] ?? "_YXMmaRPOK05Gzztl9lds";

            Rnd = DateTime.Now.ToString("dd.MM.yyyy H:mm:ss", CultureInfo.InvariantCulture);

            var raw = $"{Sx}|{ClientRefCode}|{Amount}|{SuccessUrl}|{FailUrl}|{Rnd}|{CustomerKey}|{merchantSecretKey}";
            using var sha512 = SHA512.Create();
            HashDataV2 = Convert.ToBase64String(sha512.ComputeHash(Encoding.UTF8.GetBytes(raw)));
        }
    }
}