<?php
// tes-bayar.php - SIMULATOR WEBHOOK UTAMA (GRATIS & TANPA UANG ASLI)
require_once 'config.php';

// 🌟 LANGKAH UTAMA: Tempelkan ID Transaksi/Invoice dari Firebase Langkah 1 di sini
$idInvoiceTarget = "66e3713e-1aeb-452c-9476-bed84478844d"; 


// 🌟 LANGKAH 2: Tulis URL Webhook2 Anda secara lengkap dan manual di sini (Hapus auto-detect)
// Contoh: "https://eltopinovatif.biz.id"
$url_webhook_lokal = "https://eltopinovatif.biz.id/webhook2.php"; 

// Menyusun Payload tiruan 100% mirip dengan data log asli dari Mayar Anda
$payload_tiruan = json_encode([
    "event" => "payment.reminder",
    "data" => [
        "id" => $idInvoiceTarget,
        "transactionId" => $idInvoiceTarget,
        "status" => "SUCCESS", // Menggunakan HURUF BESAR sesuai data asli lapangan
        "amount" => 35000
    ]
]);

// Kirim data menggunakan cURL POST ke webhook2.php
$ch = curl_init($url_webhook_lokal);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_tiruan);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);

echo "<h3>--- STATUS SIMULATOR PEMBAYARAN ---</h3>";
if ($err) {
    echo "Gagal menghubungi server Webhook: " . htmlspecialchars($err);
} else {
    echo "<b>URL Webhook yang Ditembak:</b> " . htmlspecialchars($url_webhook_lokal) . "<br><br>";
    echo "<b>Respon Balikan dari Webhook2:</b> <br><pre style='background:#eee; padding:10px; border-radius:5px;'>" . htmlspecialchars($response) . "</pre>";
}
?>
