37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
require_once '../midtrans'; // File konfigurasi Midtrans
|
|
|
|
// Data transaksi untuk QRIS
|
|
$order_id = $id_order; // Gunakan ID pesanan sebagai order_id
|
|
// Data transaksi untuk QRIS
|
|
$qris_params = [
|
|
'payment_type' => 'qris',
|
|
'transaction_details' => [
|
|
'order_id' => $id_order, // ID order dari tabel orders
|
|
'gross_amount' => $total_harga, // Total harga
|
|
],
|
|
'customer_details' => [
|
|
'first_name' => $_SESSION['nama_pembeli'], // Nama pembeli dari session
|
|
'email' => $_SESSION['email_pembeli'], // Email pembeli dari session
|
|
],
|
|
];
|
|
|
|
try {
|
|
// Kirim permintaan ke Midtrans API
|
|
$response = \Midtrans\CoreApi::charge($qris_params);
|
|
|
|
// Ambil QRIS URL dari respons
|
|
$qris_url = $response->actions[0]->url;
|
|
|
|
// Simpan QRIS URL ke database
|
|
$query_update_qris = "UPDATE orders SET qris_url = '$qris_url' WHERE id_order = '$id_order'";
|
|
mysqli_query($conn, $query_update_qris);
|
|
|
|
// Redirect ke halaman QRIS
|
|
echo "<script>alert('Silakan lakukan pembayaran menggunakan QRIS.');window.location='/qris?id_order=$id_order';</script>";
|
|
exit;
|
|
} catch (Exception $e) {
|
|
echo "<script>alert('Gagal membuat QRIS: " . $e->getMessage() . "');window.history.back();</script>";
|
|
}
|
|
|
|
?>
|