Siteβ―Builder
Editing:
subscriptions.php
writable 0666
<?php /***************************************************************** * Subscriber centre + link to Stripe Billing Portal (hardened) *****************************************************************/ require_once __DIR__.'/lib/auth.php'; require_login(); require_once __DIR__.'/lib/db.php'; require_once __DIR__.'/lib/config.php'; require_once $_SERVER['HOME'].'/vendor/autoload.php'; \Stripe\Stripe::setApiKey($_ENV['STRIPE_SECRET']); $u = current_user(); /*ββββββββββββββββββββββββββββ 1. Create portal session on POST ββ*/ if (isset($_POST['manage']) && $u['stripe_customer_id']) { try { $portal = \Stripe\BillingPortal\Session::create([ 'customer' => $u['stripe_customer_id'], 'return_url' => SITE_URL . '/members/subscriptions.php', ]); header('Location: ' . $portal->url); exit; } catch (\Stripe\Exception\ApiErrorException $e) { // Log full payload for debugging, show friendly msg to user file_put_contents( '/tmp/bdo_stripe_portal.log', date('[Y-m-d H:i:s] ') . $e->getMessage() . PHP_EOL, FILE_APPEND ); $flash = 'Stripe returned an error while opening the portal. ' . 'Please try again later or contact support.'; } } /*ββββββββββββββββββββββββββββ 2. Facts for display ββββββββββββ*/ $isPremium = $u['premium_until'] && (strtotime($u['premium_until']) > time()); $daysLeft = $isPremium ? floor((strtotime($u['premium_until']) - time()) / 86400) : 0; ?> <!doctype html> <title>Your Subscription βΒ BestDealOn</title> <meta name=viewport content="width=device-width,initial-scale=1"> <style> *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif} body{margin:0;background:#fafafa;color:#111;line-height:1.44} main{max-width:540px;margin:3rem auto;padding:0 1.2rem} h1{margin:0 0 1.4rem;font-size:1.9rem} section{background:#fff;border:1px solid #ddd;border-radius:6px;padding:1.4rem;margin-bottom:1.8rem} .row{display:flex;justify-content:space-between;margin:.35rem 0} label{color:#555} button{display:block;width:100%;padding:.8rem 1rem;margin-top:1.2rem;background:#0073e6;color:#fff;border:0;border-radius:4px;font-size:1rem;font-weight:600;cursor:pointer} button:hover{background:#005fc2} .notice{background:#ffecc0;padding:.8rem 1rem;border-radius:6px;border:1px solid #f2d98f} .flash{color:#c00;margin-bottom:1rem;font-weight:600} </style> <main> <h1>Subscription centre</h1> <?php if (!empty($flash)): ?> <p class=flash><?= htmlspecialchars($flash) ?></p> <?php endif; ?> <section> <div class=row><label>Name</label><div><?= htmlspecialchars($u['google_name'] ?: $u['username']) ?></div></div> <div class=row><label>Eβmail</label><div><?= htmlspecialchars($u['email']) ?></div></div> <div class=row><label>AccountΒ type</label><div><?= htmlspecialchars($u['acct_type']) ?></div></div> <?php if ($isPremium): ?> <div class=row><label>Premium until</label> <div><?= htmlspecialchars($u['premium_until']) ?>Β (<?= $daysLeft ?>Β days)</div></div> <?php else: ?> <div class="notice">You do not currently have an active Premium subscription.</div> <?php endif ?> </section> <?php if ($u['stripe_customer_id']): ?> <form method=post> <button name=manage value=1>Manage / cancel subscription</button> </form> <?php else: ?> <a href="/members/stripe/checkout.php"> <button style="background:#28a745">Upgrade to Premium</button> </a> <?php endif ?> <p style="margin-top:2.5rem"> <a href="/members/dashboard.php">βΒ Back to dashboard</a> </p> </main>
Save changes
Create folder
writable 0777
Create
Cancel