prepare("SELECT * FROM cases WHERE id = ?"); $stmt->execute([$case_id]); $case = $stmt->fetch(); if (!$case) { die("Case not found"); } // Create pending donation $sql = "INSERT INTO donations (case_id, amount, status, donor_name, donor_email, donor_phone, is_gift, gift_recipient_name, gift_recipient_phone, gift_message) VALUES (?, ?, 'pending', ?, ?, ?, ?, ?, ?, ?)"; $stmt = $pdo->prepare($sql); $stmt->execute([$case_id, $amount, $donor_name, $donor_email, $donor_phone, $is_gift, $gift_recipient_name, $gift_recipient_phone, $gift_message]); $donation_id = $pdo->lastInsertId(); // Thawani Checkout Session Request $payload = [ 'client_reference_id' => (string)$donation_id, 'mode' => 'payment', 'products' => [ [ 'name' => ($is_gift ? "Gift Donation: " : "") . $case['title_en'], 'unit_amount' => (int)($amount * 1000), // Thawani uses OMR baiza (1 OMR = 1000 baiza) 'quantity' => 1 ] ], 'success_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/success.php?session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/index.php', 'metadata' => [ 'donation_id' => $donation_id, 'case_id' => $case_id ] ]; // Check if keys are default/empty if (THAWANI_SECRET_KEY === 'rRQ26GcsZ60u9Y9v9876543210' || empty(THAWANI_SECRET_KEY)) { // Simulation Mode ?> Simulating Thawani Checkout
Thawani

Thawani Checkout Simulation

Donation ID: #

Amount: OMR

Gift for: ()
This is a simulation because no valid Thawani keys are configured in db/thawani_config.php.
Cancel
prepare("UPDATE donations SET transaction_id = ? WHERE id = ?"); $stmt->execute([$session_id, $donation_id]); $checkout_url = (THAWANI_ENV === 'sandbox') ? "https://uatcheckout.thawani.om/pay/" . $session_id . "?key=" . THAWANI_PUBLISHABLE_KEY : "https://checkout.thawani.om/pay/" . $session_id . "?key=" . THAWANI_PUBLISHABLE_KEY; header("Location: " . $checkout_url); exit; } else { echo "

Thawani Error

"; echo "
";
    print_r($data);
    echo "
"; echo "Go Back"; }