<?php
require 'vendor/autoload.php';

\Stripe\Stripe::setApiKey('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');

$invoiceId = $_POST['invoice_id'];
$amount = (float)$_POST['amount'];
$email = $_POST['client_email'];
$name = $_POST['client_name'];

try {

    $session = \Stripe\Checkout\Session::create([
        'payment_method_types' => ['klarna'],
        'mode' => 'payment',

        'customer_email' => $email,

        'line_items' => [[
            'price_data' => [
                'currency' => 'usd',
                'product_data' => [
                    'name' => "Invoice #{$invoiceId}",
                ],
                'unit_amount' => (int)($amount * 100),
            ],
            'quantity' => 1,
        ]],

        'success_url' => 'https://YOURDOMAIN.com/success.php?invoice=' . $invoiceId,
        'cancel_url' => 'https://YOURDOMAIN.com/cancel.php?invoice=' . $invoiceId,
    ]);

    header("Location: " . $session->url);
    exit;

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