prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'"); $stmt->execute([$donation_id]); $donation = $stmt->fetch(); } else { // Real Thawani verification $ch = curl_init(THAWANI_API_URL . '/checkout/session/' . $session_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'thawani-api-key: ' . THAWANI_SECRET_KEY ]); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); if (isset($data['success']) && $data['success'] === true && $data['data']['payment_status'] === 'paid') { $donation_id = $data['data']['client_reference_id']; $stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'"); $stmt->execute([$donation_id]); $donation = $stmt->fetch(); } } // 2. Process success if ($donation) { // Update donation status $pdo->prepare("UPDATE donations SET status = 'completed', transaction_id = ? WHERE id = ?") ->execute([$session_id, $donation['id']]); // Update case raised amount $pdo->prepare("UPDATE cases SET raised = raised + ? WHERE id = ?") ->execute([$donation['amount'], $donation['case_id']]); // Refresh donation data to get name/phone/gift info $stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ?"); $stmt->execute([$donation['id']]); $fullDonation = $stmt->fetch(); // Send WhatsApp notification to donor WablasService::sendThankYou($fullDonation); // Send WhatsApp notification to recipient if it's a gift if ($fullDonation['is_gift']) { WablasService::sendGiftNotification($fullDonation); } $success = true; } else { // Check if it was already completed (user refreshed page) $stmt = $pdo->prepare("SELECT * FROM donations transaction_id = ? AND status = 'completed'"); $stmt->execute([$session_id]); if ($stmt->fetch()) { $success = true; } } ?>
Your donation has been successfully processed. Your generosity helps us continue our mission.
Confirmation messages have been sent to the relevant parties.
Return to HomeWe couldn't verify your payment. If you believe this is an error, please contact support.
Back to Home