prepare("SELECT * FROM cases WHERE id = ?"); $stmt->execute([$case_id]); $case = $stmt->fetch(); if (!$case) { die("Case not found"); } // Create pending donation $stmt = $pdo->prepare("INSERT INTO donations (case_id, amount, status, donor_name, donor_email, donor_phone) VALUES (?, ?, 'pending', ?, ?, ?)"); $stmt->execute([$case_id, $amount, $donor_name, $donor_email, $donor_phone]); $donation_id = $pdo->lastInsertId(); // Thawani Checkout Session Request $payload = [ 'client_reference_id' => (string)$donation_id, 'products' => [ [ 'name' => $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 ] ]; // In a real scenario, we'd use CURL to call Thawani API. // Since we don't have real keys, we'll mock the redirect or show a simulation. if (THAWANI_SECRET_KEY === 'rRQ26GcsZ60u9Y9v9876543210' || empty(THAWANI_SECRET_KEY)) { // Simulation Mode ?>
Donation ID: #= $donation_id ?>
Amount: OMR = number_format($amount, 3) ?>
db/thawani_config.php.