Skip to content

PHP API, Hooks & CLI

<?php namespace ProcessWire;
$packages = Packages::requireInstance($wire);
// Storefront catalog & page bindings
$packages->catalog();
$packages->package('booking-kit');
$packages->userPackageAccess($user, 'booking-kit');
$packages->packageForPage($page);
$packages->bundleForPage($page);
$packages->packageForDocsPage($page);
$packages->packagesForDocsPage($page);
$packages->bundleForDocsPage($page);
$packages->bundlesForDocsPage($page);
// License provisioning, ledger & portal resolvers
$packages->grantLicense($options);
$packages->renewLicense($licenseId, $days);
$packages->upgradeLicense($licenseId, $newTierKey);
$packages->recordBillingRecord($payload);
$packages->registerPortalAuthResolver($authClosure);
$packages->registerPortalBillingResolver($billingClosure);
$packages->registerPortalInvoicePdfResolver($invoicePdfClosure);
Hook Arguments & Return Timing What It Does
Packages::grantLicense (array $payload): array Before / After Issues one or more customer licenses for a package or bundle and returns the issued key details.
Packages::renewLicense (string $idOrExternalRef, ?int $updatesUntil = null, ?int $expiresAt = null, int $addDays = 365, array $meta = [], ?string $idempotencyKey = null): EntryItem Before / After Extends a license’s update window or expiry date on renewal.
Packages::upgradeLicense (string $idOrExternalRef, string $newTierIdOrKey, ?int $updatesUntil = null, ?int $expiresAt = null): EntryItem Before / After Upgrades a license to a higher tier (for example pro -> agency).
Packages::suspendLicense (string $idOrExternalRef, string $reason = ''): EntryItem Before / After Temporarily suspends a license (for example on past-due billing).
Packages::revokeLicense (string $idOrExternalRef, string $reason = ''): EntryItem Before / After Permanently revokes a license (for example after a refund or chargeback).
Packages::recordBillingRecord (array $payload): EntryItem Before / After Writes an immutable billing ledger row for orders, renewals, or refunds.
Packages::syncPackage (EntryItem $package, bool $force = false): array Before / After Synchronizes release tags and archives from a configured GitHub repository.
Packages::publishArchive (EntryItem $package, string $sourceZipPath, string $versionTag, string $changelogMarkdown = '', bool $isPrerelease = false, string $origin = 'ci_push', string $sourceRef = ''): array Before / After Publishes a local ZIP archive as a versioned release with SHA-1 and SHA-256 checksums.
Packages::renderPortal (string $screen = 'dashboard', array $props = [], ?array $flash = null): string Before / After Renders classic server-rendered /portal/* HTML screens.
Packages::renderPortalInertia (string $component, array $props = [], string $currentUrl = ''): string Before / After Renders Inertia-powered /portal/* React screens.
Packages::resolveMoney (int $amountMinor, string $currency): ?object After Customizes resolved tier/bundle Money pricing before checkout (discounts, regional pricing).
Packages::createCheckoutLink (array $options): array Before / After Customizes one-time or renewal Payments checkout link parameters.
Packages::createSubscriptionCheckout (array $options): array Before / After Customizes recurring Payments subscription checkout parameters.
Packages::forwardWebhook (string $event, array $payload): void After Inspects or forwards outbound packages.* webhook payloads.
Packages::translations (): array After Overrides or extends Customer Portal /portal/* UI translation strings.
ProcessPackages::translations (): array After Overrides or extends admin Setup -> Packages React workspace strings.
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Entries\Entity\EntryItem;
// 1. Log newly issued licenses and trigger welcome onboarding
$wire->addHookAfter('Packages::grantLicense', function (HookEvent $event): void {
$result = (array) $event->return;
$count = count((array) ($result['licenses'] ?? []));
$event->wire()->log->save('packages-licenses', "Issued {$count} new license(s).");
});
// 2. React when a license is revoked so external entitlements are cleared
$wire->addHookAfter('Packages::revokeLicense', function (HookEvent $event): void {
$licenseRef = (string) $event->arguments(0);
$reason = (string) $event->arguments(1);
$event->wire()->log->save('packages-licenses', "Revoked {$licenseRef}: {$reason}");
});
// 3. Announce newly published release archives
$wire->addHookAfter('Packages::publishArchive', function (HookEvent $event): void {
/** @var EntryItem $package */
$package = $event->arguments(0);
$versionTag = (string) $event->arguments(2);
$event->wire()->log->save('packages-releases', "Published {$package->get('slug')} {$versionTag}");
});

Run all commands via php vendor/bin/wire <command>:

Command Options & Arguments Purpose
packages:sync [<slug>], --all, --force, --json Synchronizes release tags and archives from configured GitHub repositories.
packages:publish <slug>, <version>, <zip-path>, --changelog, --prerelease, --json Publishes a local ZIP archive directly as a versioned release with SHA-1 and SHA-256 checksums.
packages:license:issue <email>, --package, --tier, --bundle, --model, --days, --domains, --quantity=1, --json Issues one or more customer licenses for a package or bundle and prints plaintext keys once.
packages:prune-logs --days=90, --dry-run, -f/--force, --json Prunes aged rows from packages_downloads and packages_rate_limits.
packages:doctor --fix, --json Audits blueprints, 4 managed SQL tables, archive storage permissions, and route health (optionally repairing with --fix).

Webhook Payload, Frontend Portal Styling, Testing, Demo Mode & Localization

Section titled “Webhook Payload, Frontend Portal Styling, Testing, Demo Mode & Localization”
  • Webhook Payload & Signature (X-Hub-Signature-256): Outbound packages.* lifecycle events forwarded via Packages::forwardWebhook use structured JSON envelopes (and inbound GitHub release webhooks are verified with X-Hub-Signature-256 using hash_equals()):
{
"event": "packages.license.granted",
"timestamp": "2026-06-15T13:00:00Z",
"data": {
"package": "booking-kit",
"tier": "pro",
"owner_email": "[email protected]"
}
}
  • Frontend Customer Portal CSS Variables (/portal/*): Override :root tokens (--font-sans, --foreground, --muted-foreground, --muted, --border, --ring) to style PackagesPortal.css to match your brand. Always exclude /portal/*, /composer/*, and /packages/api/* from full-page caches.
  • Mocking GitHub & Mirror Downloads in Pest/PHPUnit: Inject a fake implementing Totoglu\Packages\Contract\HttpTransportInterface via $packages->setHttpTransport($fakeTransport) so release sync and download tests stay offline.
  • Demo Mode ($config->demo = true): Blocks destructive license revocations, archive deletions, and release publishes.
  • 6-Locale Translation Packs: Bundled CSV packs (en, tr, de, fr, es, ru) live in site/modules/Packages/languages/ for import under Setup -> Languages -> [Language] -> Site Translation Files.

Composer Returns 401 Unauthorized on /composer/p2/...

Section titled “Composer Returns 401 Unauthorized on /composer/p2/...”
  • Verify the customer configured HTTP Basic with their exact license owner email as username and either an active pkg_tok_... Composer token or their license key as password.
  • Confirm the license is active (not suspended or revoked) and covers the requested package or bundle.

POST /packages/api/verify Rejects Requests With domain_required

Section titled “POST /packages/api/verify Rejects Requests With domain_required”
  • Strict domain enforcement (strict) is enabled in Registry Settings. Include a valid domain field in the JSON payload. Local/staging hosts (localhost, *.test, *.ddev.site, staging.*) are accepted without consuming production site slots.

Direct Requests to /site/assets/packages/*.zip Succeed Without Auth

Section titled “Direct Requests to /site/assets/packages/*.zip Succeed Without Auth”
  • Add the Nginx location ^~ /site/assets/packages/ { return 403; } block and run php vendor/bin/wire packages:doctor --fix --json to verify storage protection.
  • Confirm the shared secret in GitHub matches the secret stored in Setup -> Packages -> Registry Settings and that GitHub sends application/json with the X-Hub-Signature-256 header.

Next steps