Perpetual license
import { Access, Billing, LicenseCredentialIssuance, LicenseCredentialRotationAcceptance, Licensing, Offer, Purchase, activateLicenseCredential, createCheckout, deactivateLicenseCredential, issueLicenseCredential, processPaymentNotification, registerOffers, revokeLicenseCredential, rotateLicenseCredential, validateLicenseCredential,} from "@byfungsi/sapa";
const desktopAccess = yield * Access.entitlements({ entitlements: ["desktop.use"], duration: "perpetual", });const desktopLicense = yield * Licensing.eligibility({ entitlement: "desktop.use", activationLimit: 3, });const desktopPurchase = yield * Purchase.parse({ key: "desktop.perpetual.access", revision: 1, provides: [desktopAccess, desktopLicense], });const desktopBilling = yield * Billing.oneTime({ price: { currency: "IDR", amount: 1_499_000n }, });const desktop = yield * Offer.parse({ key: "desktop.perpetual", revision: 1, purchase: desktopPurchase, billing: desktopBilling, });
yield * registerOffers([desktop]);yield * createCheckout({ type: "offer", offerKey: desktop.key, offerRevision: desktop.revision, quantity: null, provider: "midtrans", customer, successUrl, cancelUrl, clientIp: null, idempotencyKey: "desktop-perpetual-42", });yield * processPaymentNotification({ provider: "midtrans", payload: rawProviderPayload, });
const issued = yield * issueLicenseCredential({ idempotencyKey: "desktop-issue-42", externalCustomerId: "customer-42", entitlement: "desktop.use", });if (!LicenseCredentialIssuance.guards.issued(issued)) return;
const activationId = "lact-00000000-0000-4000-8000-000000000042";yield * activateLicenseCredential({ key: issued.key, activationId });yield * validateLicenseCredential({ key: issued.key, activationId });
const rotated = yield * rotateLicenseCredential({ idempotencyKey: "desktop-rotate-42", licenseId: issued.credential.licenseId, });if (LicenseCredentialRotationAcceptance.guards.rotated(rotated)) { yield * validateLicenseCredential({ key: rotated.key, activationId }); yield * deactivateLicenseCredential({ key: rotated.key, activationId });}
yield * revokeLicenseCredential({ idempotencyKey: "desktop-revoke-42", licenseId: issued.credential.licenseId, });Rotation returns the replacement secret once and makes the old key unusable; existing activation identities carry forward. Deactivation ends one device activation and frees capacity. Revocation is merchant-controlled and terminal for every activation. “Perpetual” means no scheduled expiry, not immunity from refund or explicit revocation.