<?php
require 'stripe/init.php'; // Path to Composer autoload

\Stripe\Stripe::setApiKey('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'); // Replace with your real key

// Get amount from URL
$amount = isset($_GET['a']) ? (float) str_replace(',', '', $_GET['a']) : 0;

// Validate amount
if ($amount <= 0) {
    die("❌ Invalid amount.");
}

// Create a Stripe Payment Link (one-time)
try {
    $product = \Stripe\Product::create([
        'name' => 'Custom Payment',
    ]);

    $price = \Stripe\Price::create([
        'unit_amount' => (int) round($amount * 100), // Stripe expects amount in cents
        'currency' => 'eur',
        'product' => $product->id,
    ]);

    $link = \Stripe\PaymentLink::create([
        'line_items' => [
            ['price' => $price->id, 'quantity' => 1],
        ],
    ]);

    // Redirect user to Stripe Payment Page
    header("Location: " . $link->url);
    exit;

} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}
