<?php
/**
 * Mercado Pago Disconnect
 * Desconecta a conta MP da loja
 */
require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/Payment/MercadoPagoOAuth.php';

use Payment\MercadoPagoOAuth;

if (!isset($_SESSION['store_id'])) {
    header('Location: /pages/login.php');
    exit;
}

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: /pages/pagamentos.php');
    exit;
}

$pdo = getDB();
$storeId = $_SESSION['store_id'];

$oauth = new MercadoPagoOAuth($pdo);
$oauth->disconnect($storeId);

header('Location: /pages/pagamentos.php?success=disconnected');
exit;
