import { createSignal, createMemo, onMount, Show, For } from 'solid-js'; import { Text, Button } from '@components'; import { useLicense, useModal } from '@util/context'; import * as packedge from '../../shared/packedge.js'; export default function License() { const { license, isLocked, maskedKey, state: licenseState, setState: setLicenseState, activate: activateLicense, deactivate: deactivateLicense, fetchPlans: fetchLicensePlans } = useLicense(); const { fire, toast } = useModal(); const [plans, setPlans] = createSignal([]); const [justActivated, setJustActivated] = createSignal(false); const [loadingPlans, setLoadingPlans] = createSignal(false); const [planTier, setPlanTier] = createSignal('personal'); // personal or agency const siteUrl = window.ajaxpress_admin_vars?.site?.url || ''; const returnUrl = `${siteUrl}/wp-admin/options-general.php?page=ajaxpress#/license`; // Get yearly and lifetime plans for current tier const yearlyPlan = createMemo(() => { const slug = planTier() === 'personal' ? 'ap-single-yearly' : 'ap-agency-yearly'; return plans().find(p => p.slug === slug); }); const lifetimePlan = createMemo(() => { const slug = planTier() === 'personal' ? 'ap-single-lifetime' : 'ap-agency-lifetime'; return plans().find(p => p.slug === slug); }); const currentTierFeatures = createMemo(() => { const isPersonal = planTier() === 'personal'; return [ { label: isPersonal ? '1 site' : '100 sites', yearly: true, lifetime: true }, { label: 'All features unlocked', yearly: true, lifetime: true }, { label: 'Updates', yearly: '1 year', lifetime: 'Lifetime' }, { label: 'Premium support', yearly: '1 year', lifetime: '5 years' }, ]; }); // A crossed-out price only when PackEdge has a real one for the plan. const originalPrice = (plan) => { const original = Number(plan?.originalPrice || plan?.original_price || 0); return original > Number(plan?.price || 0) ? original : 0; }; const focus = () => { setTimeout(() => { const inputkey = document.querySelector('input.inputkey'); if (inputkey) inputkey.focus(); }, 50); }; const fetchPlans = async () => { if (!navigator.onLine) { return; } setLoadingPlans(true); const result = await fetchLicensePlans(); if (result.success && result.plans) { setPlans(result.plans); } setLoadingPlans(false); }; const activate = async () => { let result = await activateLicense(); if (result.success) { setJustActivated(true); return; } return fire({ cancel: false, title: 'License Error!', content: result.message || 'The license key you entered is invalid, please try again with valid license. Please contact ArrayStory for further details.' }).then(focus); }; const deactivate = async () => { const confirmed = await fire({ title: 'Are you sure', content: 'Are you really want to deactivate the license?', ok: 'Yes, deactivate', okVariant: 'danger', }); if (confirmed) { let result = await deactivateLicense(); if (result.success) { toast('License deactivated!'); // Focus input field focus(); } } }; const formatDate = (dateStr) => { if (!dateStr || dateStr === 'never') return 'Never'; const date = new Date(dateStr); return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); }; onMount(async () => { focus(); // Post-purchase return from PackEdge checkout: auto-activate the key, or // show a notice if the license is still being provisioned. const purchase = packedge.consumeActivationFromUrl(); if (purchase && purchase.key && isLocked()) { setLicenseState('key', purchase.key); setLicenseState('error', ''); setTimeout(async () => { await activate(); }, 50); } else if (purchase && purchase.pending) { toast('Payment received! Your license is being provisioned and will activate shortly - it has also been emailed to you.'); } // Plans come from PackEdge, so they load only when the admin asks // for them (See plans and pricing), never just by opening this screen. }); return (
{/* Header */} {/*

License

Manage your AjaxPress license and unlock premium features

*/} {/* License Card */}
{ e.preventDefault(); isLocked() ? activate() : deactivate(); }} >
{isLocked() ? 'Inactive' : 'Active'}
} > setLicenseState('key', e.target.value)} disabled={licenseState.isLoading} size="sm" />
{/* Welcome Notice */}

Welcome to AjaxPress Pro!

Your license has been activated successfully. All premium features are now unlocked.

Get priority support →
{/* Error Messages */}
Please check your internet connection. Your license is invalid or has been deactivated.
{/* Pricing Plans */}

Loads current plans and prices from PackEdge, our licensing service.

0}>
{/* Header with Toggle */}

Choose Your Plan

{/* Pricing Table */}
{/* Table Header with Prices */}
What's included
Yearly
${originalPrice(yearlyPlan())}
${yearlyPlan().price}/yr
Lifetime
${originalPrice(lifetimePlan())}
${lifetimePlan().price}
{/* Feature Rows */} {(feature) => (
{feature.label}
-}> }> {feature.yearly}
-}> }> {feature.lifetime}
)}
{/* CTA Row */}
75% OFF
Activations {license.activations || 0} / {license.activation_limit || 'Unlimited'}
Remaining {license.activations_remaining} {license.activations_remaining == 1 ? 'site' : 'sites'}
Expires {license.expires_at && license.expires_at !== 'never' ? formatDate(license.expires_at) : 'Never'}
); }