<?php

include 'config.php'; // DB connect

$amount  = $_POST['amount'] ?? '';
$trx     = $_POST['TRX'] ?? '';
$gateway = $_POST['Gateway'] ?? '';
$method  = $_POST['Method'] ?? '';
$status  = $_POST['Status'] ?? '0';
$sender  = $_POST['Sender'] ?? '';

if (empty($amount) || empty($trx) || empty($gateway) || empty($sender)) {
    echo "Missing Field";
    exit;
}

// 12-hour format date-time (example: 2025-11-29 07:22 PM)
$created_at = date("Y-m-d h:i A");

// Insert query with created_at
$sql = "INSERT INTO ShuvoPays (`from`, sender, amount, trnxid, Gateway, Method, status, created_at)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

$stmt = $conn->prepare($sql);
$stmt->bind_param("ssdsssss", 
    $gateway, 
    $sender, 
    $amount, 
    $trx, 
    $gateway, 
    $method, 
    $status,
    $created_at
);

if ($stmt->execute()) {
    echo "Added Successfully";
} else {
    echo "Failed";
}

$stmt->close();
$conn->close();

?>