<?php
require '../core/db.php';
require '../core/auth.php';
require '../core/ledger.php';

$user = requireAuth(); // session-based auth

$amount = (float) $_POST['amount'];
$method = $_POST['method'];

if ($amount < 1000) {
  die("Invalid amount");
}

if (!in_array($method, ['mtn', 'airtel'])) {
  die("Invalid payment method");
}

/*
  REAL FLOW LATER:
  - call PSP
  - wait for webhook
*/

// For now: mock success
createTransaction($user['id'], 'topup', $amount, 'pending');

header("Location: /transactions.php");
exit;
