Configuration::getConfig('premium_amount_max')) { header('Location: /support?fail=true'); } else { // Calculate the total $total = (float)Configuration::getConfig('premium_price_per_month') * (int)$_POST['months']; $total = money_format('%!i', $total); // Generate item name $itemName = 'Flashii Tenshi - '. (string)$_POST['months'] .' month'. ((int)$_POST['months'] == 1 ? '' : 's'); // Attempt to create a transaction if($transaction = Payments::createTransaction($total, $itemName, 'Flashii Tenshi Purchase', 'http://'. Configuration::getLocalConfig('urls', 'main') .'/support')) { // Store the amount of months in the global session array $_SESSION['premiumMonths'] = (int)$_POST['months']; header('Location: '. $transaction); exit; } else { header('Location: /support?fail=true'); } } break; // Finalising the purchase case 'finish': // Check if the success GET request is set and is true if(isset($_GET['success']) && isset($_GET['paymentId']) && isset($_GET['PayerID']) && isset($_SESSION['premiumMonths'])) { // Attempt to complete the transaction try{ $finalise = Payments::completeTransaction($_GET['paymentId'], $_GET['PayerID']); } catch(Exception $e) {} // Attempt to complete the transaction if($finalise) { // Make the user premium $expiration = Users::addUserPremium(Session::$userId, (2628000 * $_SESSION['premiumMonths'])); Users::updatePremiumMeta(Session::$userId); // Redirect to the complete header('Location: ?mode=complete&expire='. $expiration); exit; } } header('Location: /support?fail=true'); break; case 'complete': print Templates::render('errors/premiumComplete.tpl', array_merge([ 'page' => [ 'title' => 'Premium purchase complete!', 'expiration' => ($prem = Users::checkUserPremium(Session::$userId)[2]) !== null ? $prem : 0 ] ], $renderData)); break; default: header('Location: /support'); break; } } exit; } // Set default variables $renderData['page'] = [ 'title' => 'Support Flashii', 'fail' => isset($_GET['fail']), 'price' => Configuration::getConfig('premium_price_per_month'), 'current' => Users::checkUserPremium(Session::$userId), 'amount_max' => Configuration::getConfig('premium_amount_max') ]; // Print page contents print Templates::render('main/support.tpl', $renderData);