Sell a package
Sell a package you publish, and let people buy it from your app.
Make the package paid
Add monetization "paid" to the package's manifest, then publish it
as you would any package
(Publish and maintain a release).
A buyer pays once for every version of the package. The purchase renews
through the registry that serves your namespace: it lapses within 30
days after that registry stops answering or your admission to the
platform ends, and a full refund, or a reversal of the payment, ends
it.
- A paid app must be sealed, so what you sell ships as compiled code (Package licenses).
- A paid library or asset pack is never sealed. Buying one delivers
its source into the buyer's project, to use and adapt in their own
packages under your terms.
datumhue pkg updatebrings it into the buyer'sdeps/folder once they own it.
A paid package may leave out license, and is then offered under your
own terms.
Set the price
The price is not in the manifest. You set it, and change it whenever you like, without publishing again:
$ datumhue login
$ datumhue pkg price @studio/levels 499 --currency usd
$ datumhue pkg price @studio/levels
- The amount is in the currency's smallest unit:
499withusdis $4.99. - Setting a price lists the package for sale. A paid package cannot be bought until it has a price.
- Without an amount,
pkg priceshows the current listing.
Your sign-in must own the package's scope; the
pkg price entry lists what else can stop
it.
Sell from your app
An app that sells asks for the commerce permission, and for
packages to install what it sells:
capabilities "commerce" "packages".
local commerce = datumhue.commerce
local root = datumhue.ui.root
local levels = datumhue.packages.info("@studio/levels")
local status = root:label({ text = "" })
local buy = root:button({ text = "Buy " .. levels.title })
local function play()
levels:install():ready()
datumhue.app.spawn({ package_ref = levels })
end
local function owned()
return commerce.check_purchase(levels):ready().value
end
local checked, owns = pcall(owned)
if checked and owns then
play()
end
buy:on_click(function()
local done, result = pcall(commerce.purchase, levels)
if not done then
status.text = "Couldn't buy " .. levels.title .. ". "
.. tostring(result)
elseif result then
play()
end
end)
commerce.check_purchaseanswers whether the signed-in person owns the package. Once known, the answer is kept on the buyer's workstation for up to 30 days, so the check does not ask datumhue.app each time.commerce.purchaseasks the buyer to confirm, opens the payment page and waits for the payment. DatumHue shows the confirmation, not your app, so no app can answer it for the buyer.- It returns nil when the buyer cancels. That is not an error: offer Buy
again. It raises when the purchase could not go ahead or failed, so
call it through
pcalland show the error as it is, after your own line saying what did not happen. The error is one plain sentence for the buyer; never parse it, since its wording can change. - A cancel also pauses your app's purchases for a few seconds, so never retry one in a loop.
- A buyer's purchases work on a limited number of devices. On a device past that limit, or one the buyer removed from their account, the check, the purchase and installing or loading a paid package raise a sentence saying so, which also names what the buyer can do.
PackageRef:monetizationgives the current price, to show beside Buy.
See also
Reference used on this page: datumhue.commerce datumhue.ui.root datumhue.packages.info UiElement:label UiElement:button PackageRef.title PackageRef:install Op:ready datumhue.app.spawn datumhue.commerce.check_purchase BoolFetch:ready BoolFetch.value UiElement:on_click datumhue.commerce.purchase UiElement.text PackageRef:monetization