<?php
// ============================================================
//  netcash-decline.php — Decline URL
// ============================================================
//
//  Netcash redirects the cardholder here when a transaction
//  is declined. Bounces logged-in members to the cancel page
//  so they can retry; otherwise shows a generic message.
//
// ============================================================
require_once __DIR__ . '/includes/auth.php';
require_once __DIR__ . '/includes/csrf.php';

$reason = $_POST['Reason'] ?? $_GET['Reason'] ?? 'Transaction declined';

if (auth_member_check()) {
    header('Location: ' . SITE_URL . '/member/payment-cancel.php?gateway=netcash&r='
        . urlencode(mb_substr((string)$reason, 0, 80)));
    exit;
}
?><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Payment declined — Buy Local Lowveld</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{font-family:system-ui,-apple-system,sans-serif;max-width:560px;margin:3rem auto;padding:0 1.25rem;color:#1f2937;}
.box{background:#fef2f2;border:1px solid #fca5a5;border-radius:10px;padding:2rem;text-align:center;}
.icon{font-size:2.5rem;margin-bottom:.5rem;}
h1{margin:0 0 .25rem;color:#991b1b;}
p{margin:.4rem 0;}
.btn{display:inline-block;background:#dc2626;color:#fff;text-decoration:none;padding:.65rem 1.4rem;border-radius:6px;font-weight:600;margin-top:1rem;}
.muted{color:#64748b;font-size:.85rem;}
</style>
</head>
<body>
<div class="box">
    <div class="icon">✕</div>
    <h1>Payment declined</h1>
    <p><?= htmlspecialchars($reason) ?></p>
    <p>You haven't been charged. Please try again or use a different payment method.</p>
    <a class="btn" href="<?= htmlspecialchars(SITE_URL) ?>/login.php">Sign in to retry</a>
</div>
</body>
</html>