Example 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="118591467|bScbGDYCtPf7SS1N6PQ6/+58rFhW1WpsWINqvkJFaJlu6bMH2tgPKDQtjeA5vClpzJP24uA0vx7OX53cP3SgUspa4EvYix+1C3aXe++8glUvu9Oyyj3v300p5NP7ro/9K57Zcw==";$merchantSecretKey="_YckdxUbv4vrnMUZ6VQsr"; // size özel - special to you$successUrl="https://paynkolay.com.tr/test/success";$failUrl="https://paynkolay.com.tr/test/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>
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; } = "118591467|bScbGDYCtPf7SS1N6PQ6/+58rFhW1WpsWINqvkJFaJlu6bMH2tgPKDQtjeA5vClpzJP24uA0vx7OX53cP3SgUspa4EvYix+1C3aXe++8glUvu9Oyyj3v300p5NP7ro/9K57Zcw=="; public string SuccessUrl { get; private set; } = "https://paynkolay.com.tr/test/success"; public string FailUrl { get; private set; } = "https://paynkolay.com.tr/test/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"] ?? "_YckdxUbv4vrnMUZ6VQsr";
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))); } }}
@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>
import hashlibimport base64from datetime import datetime
def generate_payment_form(): """ Generates an HTML form for the payment gateway with a calculated hash. This function replicates the logic from the original PHP script. """ # 1. Define your payment parameters # This value will be provided to you by the payment gateway sx = "118591467|bScbGDYCtPf7SS1N6PQ6/+58rFhW1WpsWINqvkJFaJlu6bMH2tgPKDQtjeA5vClpzJP24uA0vx7OX53cP3SgUspa4EvYix+1C3aXe++8glUvu9Oyyj3v300p5NP7ro/9K57Zcw==" merchant_secret_key = "_YckdxUbv4vrnMUZ6VQsr" # Your unique secret key success_url = "https://paynkolay.com.tr/test/success" fail_url = "https://paynkolay.com.tr/test/fail" amount = "1.00" client_ref_code = "2352345" use_3d = "true" agent_code = "1236" transaction_type = "sales" customer_key = ""
# Get the current timestamp in the required format rnd = datetime.now().strftime("%d.%m.%Y %H:%M:%S")
# 2. Create the hash string by concatenating the values # The order of concatenation is crucial and must match the payment gateway's documentation. hash_str_parts = [ sx, client_ref_code, amount, success_url, fail_url, rnd, customer_key, merchant_secret_key ] hash_str = "|".join(hash_str_parts)
# 3. Calculate the SHA-512 hash and then Base64 encode it # First, encode the string to bytes using UTF-8 hash_bytes = hash_str.encode('utf-8')
# Calculate the SHA-512 hash, getting the raw binary output (digest) sha512_hash_digest = hashlib.sha512(hash_bytes).digest()
# Base64 encode the raw hash digest hash_data_v2_bytes = base64.b64encode(sha512_hash_digest)
# Decode the Base64 bytes into a string to use in the HTML form hash_data_v2 = hash_data_v2_bytes.decode('utf-8')
# 4. Generate the HTML content using an f-string html_content = f"""<!doctype html><html><head><title>Sanal POS entegrasyonu örnek Python sayfamız</title><meta charset="utf-8"></head><body>
<h2>Payment Form (Generated by Python)</h2><p>Click the button below to proceed to the payment page.</p>
<form method="post" action="https://paynkolaytest.nkolayislem.com.tr/Vpos"> <input type="hidden" name="sx" value="{sx}"> <input type="hidden" name="successUrl" value="{success_url}"> <input type="hidden" name="failUrl" value="{fail_url}"> <input type="hidden" name="amount" value="{amount}"> <input type="hidden" name="clientRefCode" value="{client_ref_code}"> <input type="hidden" name="use3D" value="{use_3d}"> <input type="hidden" name="rnd" value="{rnd}"> <input type="hidden" name="agentCode" value="{agent_code}"> <input type="hidden" name="transactionType" value="{transaction_type}"> <input type="hidden" name="hashDataV2" value="{hash_data_v2}"> <input type="submit" value="Gönder" style="padding: 10px 20px; font-size: 16px; cursor: pointer;" /></form>
</body></html>"""
# 5. Save the generated HTML to a file try: with open("payment_form.html", "w", encoding="utf-8") as f: f.write(html_content) print("Successfully created 'payment_form.html'.") print("Open this file in your browser to submit the form.") except IOError as e: print(f"Error writing to file: {e}")
if __name__ == "__main__": generate_payment_form()
const crypto = require('crypto');const fs = require('fs');
/** * Generates an HTML form for the payment gateway with a calculated hash. * This function replicates the logic from the original PHP/Python scripts. */function generatePaymentForm() { // 1. Define your payment parameters using the new values const sx = "118591467|bScbGDYCtPf7SS1N6PQ6/+58rFhW1WpsWINqvkJFaJlu6bMH2tgPKDQtjeA5vClpzJP24uA0vx7OX53cP3SgUspa4EvYix+1C3aXe++8glUvu9Oyyj3v300p5NP7ro/9K57Zcw=="; const merchantSecretKey = "_YckdxUbv4vrnMUZ6VQsr"; // Your unique secret key const successUrl = "https://paynkolay.com.tr/test/success"; const failUrl = "https://paynkolay.com.tr/test/fail"; const amount = "1.00"; const clientRefCode = "2352345"; const use3D = "true"; const agentCode = "1236"; const transactionType = "sales"; const customerKey = "";
// Helper function to format the date as "dd.mm.yyyy HH:MM:SS" const getFormattedDate = () => { const now = new Date(); const pad = (num) => num.toString().padStart(2, '0');
const day = pad(now.getDate()); const month = pad(now.getMonth() + 1); // Months are 0-indexed const year = now.getFullYear();
const hours = pad(now.getHours()); const minutes = pad(now.getMinutes()); const seconds = pad(now.getSeconds());
return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`; };
const rnd = getFormattedDate();
// 2. Create the hash string by concatenating the values // The order of concatenation is crucial. const hashStrParts = [ sx, clientRefCode, amount, successUrl, failUrl, rnd, customerKey, merchantSecretKey ]; const hashStr = hashStrParts.join("|");
// 3. Calculate the SHA-512 hash and then Base64 encode it const hash = crypto.createHash('sha512'); hash.update(hashStr, 'utf-8'); const hashDataV2 = hash.digest('base64');
// 4. Generate the HTML content using a template literal const htmlContent = `<!doctype html><html><head><title>Sanal POS entegrasyonu örnek Node.js sayfamız</title><meta charset="utf-8"></head><body>
<h2>Payment Form (Generated by Node.js)</h2><p>Click the button below to proceed to the payment page.</p>
<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" style="padding: 10px 20px; font-size: 16px; cursor: pointer;" /></form>
</body></html>`;
// 5. Save the generated HTML to a file try { fs.writeFileSync('payment_form_node.html', htmlContent, { encoding: 'utf-8' }); console.log("Successfully created 'payment_form_node.html'."); console.log("Open this file in your browser to submit the form."); } catch (err) { console.error("Error writing to file:", err); }}
// Run the functiongeneratePaymentForm();
Test Environment
Section titled “Test Environment”You can use the following test page to test your integration: