# Start shipping sites
$79 one-time purchase — no subscription, no lock-in.

- **$79 one-time purchase covers your first 3 deployed sites**
- No subscription, host your sites anywhere
- Includes all [premium features](/docs/build-modes#premium-features+newtab) and [future updates](/docs/updates+newtab)

<div class="auth-form">

<div id="upgrade-logged-in" style="display:none">

<div class="auth-error" id="upgrade-error-loggedin"></div>

<button class="auth-submit" id="upgrade-buy-btn" type="button">Purchase →</button>

<p class="auth-link" style="font-size:0.85em">By purchasing, you agree to our <a href="/terms-of-service">Terms of Service</a> and <a href="/privacy-policy">Privacy Policy</a>.</p>

<p class="auth-link">Need more sites? <a href="/account/add-ons">Add-on site slots</a> are $19 each.</p>

</div>

<div id="upgrade-purchase-form">

<div class="auth-error" id="upgrade-error"></div>

<label for="upgrade-email">Email</label>
<input type="email" id="upgrade-email" autocomplete="email" placeholder="you@example.com" required>

<div id="upgrade-password-field" style="display:none">
<label for="upgrade-password">Password</label>
<input type="password" id="upgrade-password" autocomplete="new-password">
</div>

<button class="auth-submit" id="upgrade-btn" type="button" disabled>Continue to Checkout →</button>

<p class="auth-link" style="font-size:0.85em">By purchasing, you agree to our <a href="/terms-of-service">Terms of Service</a> and <a href="/privacy-policy">Privacy Policy</a>.</p>

<p class="auth-link">Already have an account? <a href="/login">Log in</a></p>

</div>

</div>

<script>
(function() {
  var cfg = window.__sitemdAuthCfg || {};
  var apiUrl = cfg.apiUrl || 'https://api.sitemd.cc';
  var isMagicLink = cfg.loginMode === 'magic-link';

  // Show password field in password mode (no auth dependency)
  if (!isMagicLink) {
    document.getElementById('upgrade-password-field').style.display = '';
    document.getElementById('upgrade-btn').textContent = 'Create Account & Checkout \u2192';
  }

  // Show post-checkout success message (no auth dependency)
  if (/[?&]checkout=success/.test(location.search)) {
    history.replaceState(null, '', location.pathname);
    var successBanner = document.createElement('div');
    successBanner.style.cssText = 'background:var(--color-accent,#16a34a);color:#fff;padding:var(--space-sm) var(--space-md);border-radius:var(--radius-md,6px);margin-bottom:var(--space-md)';
    successBanner.textContent = 'Payment received! Check your email for a login link to access your account.';
    var purchaseForm = document.getElementById('upgrade-purchase-form');
    purchaseForm.parentNode.insertBefore(successBanner, purchaseForm);
  }

  function init() {
    var auth = window.__sitemdAuth;

    function startCheckout(email, token) {
      var headers = { 'Content-Type': 'application/json' };
      if (token) headers['Authorization'] = 'Bearer ' + token;
      var body = isMagicLink ? { product: 'starter', email: email } : { product: 'starter' };
      return fetch(apiUrl + '/checkout/session', {
        method: 'POST',
        headers: headers,
        body: JSON.stringify(body),
      })
        .then(function(r) { return r.json(); })
        .then(function(data) {
          if (!data.url) throw new Error(data.error || 'Could not start checkout');
          if (isMagicLink) { window.open(data.url, '_blank'); } else { location.href = data.url; }
        });
    }

    if (auth && auth.isLoggedIn()) {
      // Already licensed → redirect to account dashboard
      auth.getLicenses().then(function(data) {
        var licenses = data.licenses || [];
        if (licenses.length > 0) {
          location.href = '/account';
          return;
        }

        document.getElementById('upgrade-logged-in').style.display = '';
        document.getElementById('upgrade-purchase-form').style.display = 'none';

        document.getElementById('upgrade-buy-btn').addEventListener('click', function() {
          var btn = this;
          var err = document.getElementById('upgrade-error-loggedin');
          btn.disabled = true;
          btn.textContent = 'Opening checkout\u2026';
          Promise.resolve(auth.getUser()).then(function(u) {
            return startCheckout((u && u.email) || '', auth.getToken());
          }).then(function() {
            btn.disabled = false;
            btn.textContent = 'Buy Now \u2192';
          }).catch(function(e) {
            err.textContent = e.message || 'Could not start checkout';
            err.classList.add('is-visible');
            btn.disabled = false;
            btn.textContent = 'Buy Now \u2192';
          });
        });
      });
      return;
    }

    var btn = document.getElementById('upgrade-btn');
    var err = document.getElementById('upgrade-error');
    var upgradeEmail = document.getElementById('upgrade-email');

    function validateUpgradeEmail() {
      var v = upgradeEmail.value.trim();
      btn.disabled = !v || v.indexOf('@') === -1;
    }
    upgradeEmail.addEventListener('input', validateUpgradeEmail);

    btn.addEventListener('click', function() {
      var email = document.getElementById('upgrade-email').value.trim();
      if (!email) return;
      err.classList.remove('is-visible');
      btn.disabled = true;

      if (!isMagicLink) {
        // Password mode: create account first, then redirect to checkout
        var password = document.getElementById('upgrade-password').value;
        if (!password) { btn.disabled = false; return; }
        btn.textContent = 'Creating account\u2026';
        auth.signup(email, password)
          .then(function() {
            btn.textContent = 'Redirecting to checkout\u2026';
            return startCheckout(email, auth.getToken());
          })
          .catch(function(e) {
            err.textContent = e.message || 'Could not create account';
            err.classList.add('is-visible');
            btn.disabled = false;
            btn.textContent = 'Create Account & Checkout \u2192';
          });
      } else {
        // Magic-link mode: open Stripe in new tab, webhook creates account
        btn.textContent = 'Opening checkout\u2026';
        startCheckout(email, null)
          .then(function() {
            btn.disabled = false;
            btn.textContent = 'Continue to Checkout \u2192';
          })
          .catch(function(e) {
            err.textContent = e.message || 'Could not start checkout';
            err.classList.add('is-visible');
            btn.disabled = false;
            btn.textContent = 'Continue to Checkout \u2192';
          });
      }
    });
  }

  if (window.__sitemdAuth) { window.__sitemdAuth.ready.then(init); }
  else { document.addEventListener('sitemd:auth-ready', init); }
})();
</script>