<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Formdan gelen veriler
    $amount = $_POST['amount']; // Örnek veri
    $cardNumber = $_POST['cardNumber']; // Örnek veri
    
    // XML oluştur
    $xmlRequest = "
        <posnetRequest>
            <mid>XXXXXXXX</mid>
            <tid>YYYYYYYY</tid>
            <tranDate>20250103</tranDate>
            <amount>{$amount}</amount>
            <ccno>{$cardNumber}</ccno>
            <cvc>123</cvc>
        </posnetRequest>
    ";
    // CURL ile bankaya isteği gönder
    $ch = curl_init('https://test.posnet.ykb.com/3Dgate');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/xml']);
    
    $response = curl_exec($ch);
    curl_close($ch);
    // Yanıtı işle ve sonucu sonuç sayfasına yönlendir
    if ($response) {
        file_put_contents('bank_response.xml', $response); // Geçici depolama
        header('Location: sonuc.php');
        exit();
    } else {
        echo "Bankaya bağlantı hatası!";
    }
} else {
    echo "Geçersiz istek!";
}
?>
<form action="istek.php" method="post">
    <label>Amount:</label>
    <input type="text" name="amount" required>
    <label>Card Number:</label>
    <input type="text" name="cardNumber" required>
    <button type="submit">Gönder</button>
</form>