<?php
/**
 * Calculate Paystack Charge API
 * Returns charge calculation for a given amount
 */

require_once '../config.php';
require_once '../app/classes/PaystackChargeManager.php';

header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode(['success' => false, 'message' => 'Method not allowed']);
    exit;
}

$input = json_decode(file_get_contents('php://input'), true);
$amount = isset($input['amount']) ? floatval($input['amount']) : 0;

if ($amount <= 0) {
    echo json_encode(['success' => false, 'message' => 'Invalid amount']);
    exit;
}

$chargeManager = new PaystackChargeManager($conn);
$calculation = $chargeManager->calculateChargedAmount($amount);

echo json_encode([
    'success' => true,
    'base_amount' => $calculation['base_amount'],
    'charge_amount' => $calculation['charge_amount'],
    'total_amount' => $calculation['total_amount'],
    'charge_type' => $calculation['charge_type']
]);
?>





























