<?php
if(!isLoggedIn()) redirect(1,'login');
echo '<div class="page-title"><span>'.lang('vip_title',true).'</span></div>';
try {
    if(($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') throw new Exception(lang('vip_error_7'));
    $token=isset($_POST['purchase_token']) ? (string)$_POST['purchase_token'] : '';
    if(!\Plugin\VIP\VIP::consumePurchaseToken($token)) throw new Exception(lang('vip_error_13'));
    if(!isset($_POST['type'],$_POST['package'])) throw new Exception(lang('vip_error_7'));
    $VIP=new \Plugin\VIP\VIP();
    $VIP->setUsername($_SESSION['username']);
    $VIP->setVipType((int)$_POST['type']);
    $VIP->setVipPackage((int)$_POST['package']);
    $VIP->getVip();
} catch(Exception $ex) { message('error',$ex->getMessage()); }
