83 lines
3.6 KiB
PHP
83 lines
3.6 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'mail/WablasService.php';
|
|
|
|
$session_id = $_GET['session_id'] ?? null;
|
|
$donation_id = $_GET['donation_id'] ?? null; // For simulation
|
|
|
|
if (!$session_id) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// In simulation we use donation_id from URL
|
|
// In real life, we'd verify session_id with Thawani API
|
|
if (strpos($session_id, 'mock_session_') === 0 && $donation_id) {
|
|
$stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'");
|
|
$stmt->execute([$donation_id]);
|
|
$donation = $stmt->fetch();
|
|
} else {
|
|
// Real Thawani verification logic would go here
|
|
// In real scenario, we'd fetch the donation record by the session_id or client_reference_id
|
|
$stmt = $pdo->prepare("SELECT * FROM donations WHERE transaction_id = ? OR id = (SELECT id FROM donations WHERE status='pending' LIMIT 1)"); // Simplified for now
|
|
// Actually, in real Thawani flow, we should query by session_id
|
|
// For now, let's keep it simple as the project seems to be in a prototype/simulation phase
|
|
$stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ? AND status = 'pending'");
|
|
$stmt->execute([$donation_id]);
|
|
$donation = $stmt->fetch();
|
|
}
|
|
|
|
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
|
|
$stmt = $pdo->prepare("SELECT * FROM donations WHERE id = ?");
|
|
$stmt->execute([$donation['id']]);
|
|
$fullDonation = $stmt->fetch();
|
|
|
|
// Send WhatsApp notification via Wablas
|
|
WablasService::sendThankYou($fullDonation);
|
|
|
|
$success = true;
|
|
} else {
|
|
$success = false;
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Donation Successful - CharityHub</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
|
|
</head>
|
|
<body class="bg-light">
|
|
<div class="container py-5 text-center">
|
|
<?php if ($success): ?>
|
|
<div class="card mx-auto p-5 shadow-sm" style="max-width: 600px; border-radius: 20px;">
|
|
<div class="text-success mb-4">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" fill="currentColor" class="bi bi-check-circle-fill" viewBox="0 0 16 16">
|
|
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
|
|
</svg>
|
|
</div>
|
|
<h2>Thank You!</h2>
|
|
<p class="lead text-muted">Your donation has been successfully processed. You have made a real difference today.</p>
|
|
<hr class="my-4">
|
|
<p class="small text-muted">A confirmation message has been sent to your WhatsApp number.</p>
|
|
<a href="index.php" class="btn btn-primary px-5 py-2 rounded-pill" style="background-color: #059669; border: none;">Back to Home</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="alert alert-danger">Something went wrong or the donation was already processed.</div>
|
|
<a href="index.php" class="btn btn-secondary">Back to Home</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</body>
|
|
</html>
|