121 lines
4.0 KiB
PHP
121 lines
4.0 KiB
PHP
<?php include '../template/template1.php'; ?>
|
|
<?php include '../template/header.php'; ?>
|
|
<?php
|
|
$id_order = $_GET['id_order'] ?? 0;
|
|
|
|
// Pastikan id_order adalah angka untuk mencegah SQL Injection
|
|
if (!filter_var($id_order, FILTER_VALIDATE_INT)) {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'ID Pesanan Tidak Valid!',
|
|
text: 'Silakan coba lagi.',
|
|
confirmButtonColor: '#d33',
|
|
confirmButtonText: 'Kembali'
|
|
}).then(() => {
|
|
window.location='/pesanan';
|
|
});
|
|
</script>";
|
|
exit;
|
|
}
|
|
|
|
// Gunakan prepared statement untuk keamanan
|
|
$stmt = $conn->prepare("SELECT status_order, total_harga FROM orders WHERE id_order = ?");
|
|
$stmt->bind_param("i", $id_order);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$order = $result->fetch_assoc();
|
|
|
|
// Jika pesanan tidak ditemukan, kembali ke halaman pesanan
|
|
if (!$order) {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Pesanan Tidak Ditemukan!',
|
|
text: 'Pesanan yang Anda cari tidak tersedia.',
|
|
confirmButtonColor: '#d33',
|
|
confirmButtonText: 'Kembali'
|
|
}).then(() => {
|
|
window.location='/pesanan';
|
|
});
|
|
</script>";
|
|
exit;
|
|
}
|
|
|
|
// Jika pembayaran sudah sukses, langsung redirect
|
|
if ($order['status_order'] === 'Pembayaran Sukses') {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Pembayaran Berhasil!',
|
|
text: 'Pesanan Anda telah dikonfirmasi.',
|
|
confirmButtonColor: '#28a745',
|
|
confirmButtonText: 'Lihat Pesanan'
|
|
}).then(() => {
|
|
window.location='/pesanan/index.php?id_order=$id_order';
|
|
});
|
|
</script>";
|
|
exit;
|
|
}
|
|
|
|
// Format angka untuk total harga (contoh: 1000000 -> 1.000.000)
|
|
$total_harga = number_format($order['total_harga'], 0, ',', '.');
|
|
?>
|
|
<style>
|
|
#qris-image {
|
|
max-width: 300px;
|
|
margin-top: 20px;
|
|
}Z
|
|
.payment-info {
|
|
font-size: 20px;
|
|
font-weight: bold;
|
|
margin-top: 10px;
|
|
}
|
|
</style>
|
|
<script>
|
|
function checkPaymentStatus() {
|
|
fetch('cek_status.php?id_order=<?php echo $id_order; ?>')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status === "Pembayaran Sukses") {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Pembayaran Berhasil!',
|
|
text: 'Pesanan Anda telah dikonfirmasi.',
|
|
confirmButtonColor: '#28a745',
|
|
confirmButtonText: 'Lihat Pesanan'
|
|
}).then(() => {
|
|
window.location = "/pesanan/index.php?id_order=<?php echo $id_order; ?>";
|
|
});
|
|
} else {
|
|
console.log("Masih menunggu pembayaran...");
|
|
setTimeout(checkPaymentStatus, 5000); // Cek lagi setelah 5 detik
|
|
}
|
|
})
|
|
.catch(error => {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Gagal Mengambil Status!',
|
|
text: 'Terjadi kesalahan dalam mengambil status pembayaran.',
|
|
confirmButtonColor: '#d33',
|
|
confirmButtonText: 'Coba Lagi'
|
|
}).then(() => {
|
|
window.location.reload();
|
|
});
|
|
});
|
|
}
|
|
|
|
setTimeout(checkPaymentStatus, 5000); // Jalankan pengecekan pertama setelah 5 detik
|
|
</script>
|
|
<body>
|
|
<div class="container"style="text-align: center;">
|
|
<h3 style="margin-top: 10%;">Menunggu Pembayaran QRIS disetujui oleh admin</h3>
|
|
<p class="payment-info">Total yang harus dibayar: Rp <?= $total_harga; ?></p>
|
|
<img id="qris-image" src="<?= $base_url; ?>/checkout/qris/qris_dana.png" alt="QRIS Code">
|
|
<p>Silakan lakukan pembayaran dan tunggu konfirmasi.</p>
|
|
</div>
|
|
</body>
|
|
|
|
<?php include '../template/footer.php'; ?>
|
|
<?php include '../template/template2.php'; ?>
|