<?php
define('SECRET_KEY', 'b208669f0d6fc2e262786a8a523a61bc');

// Step 1: Build the transdata array
$transdata = [
    "order_no" => "202508131755083219656361",
    "order_time" => 1755083220000,
    "product_code" => "1",
    "product_name" => "test1",
    "user_no" => "1",
    "order_amount" => "500.000",
    "pay_type" => "india-upi",
    "payment" => "支付成功"
];

// Step 2: Sign the data
ksort($transdata);
$sign_str = '';
foreach ($transdata as $k => $v) {
    if ($v !== '') {
        $sign_str .= "$k=$v&";
    }
}
$sign_str .= "key=" . SECRET_KEY;
$sign = strtoupper(md5($sign_str));

// Step 3: Prepare full payload
$payload = [
    "sign" => $sign,
    "transdata" => urlencode(json_encode($transdata, JSON_UNESCAPED_UNICODE))
];

// Step 4: Send using cURL
$callbackUrl = 'https://kilicow.rdnslvhost.in.net/payinr/callbackv1'; // replace this

$ch = curl_init($callbackUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

// Output
header('Content-Type: text/plain');
echo "Callback sent to: $callbackUrl\n";
echo "HTTP Code: $http_code\n";
echo "Request Payload:\n" . json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
echo "Response:\n$response\n";
if ($error) {
    echo "cURL Error: $error\n";
}
?>
