<?php
// stripe_onboarding_refresh.php

require_once 'config.php';

try {
    $accountId = $_GET['account_id'] ?? null;
    $userId = $_GET['user_id'] ?? null;

    if (!$accountId || !$userId) {
        throw new Exception("Parametri mancanti.");
    }

    // Ricrea l'AccountLink
    $account_link = \Stripe\AccountLink::create([
        'account' => $accountId,
        'refresh_url' => YOUR_PLATFORM_URL . '/stripe_onboarding_refresh.php?account_id=' . $accountId . '&user_id=' . $userId,
        'return_url' => YOUR_PLATFORM_URL . '/stripe_onboarding_return.php?account_id=' . $accountId . '&user_id=' . $userId,
        'type' => 'account_onboarding',
        'collection_options' => [
            'fields' => 'currently_due',
            'future_requirements' => 'include',
        ],
    ]);

    header("Location: " . $account_link->url);
    exit();

} catch (Exception $e) {
    http_response_code(500);
    echo "<h1>Errore durante il refresh dell'onboarding:</h1>";
    echo "<p>" . $e->getMessage() . "</p>";
}
?>