Selling in your app
Selling: list, start, come back
List what's on sale
curl "https://gateway.nostrad.ai/v1/products?ids=coins_100,level_2" -H "Authorization: Bearer $ACCESS_TOKEN"
{ "products": [ { "id": "coins_100", "type": "consumable", "name": "100 coins", "description": "A bag of coins",
"price": { "credits": 199, "usd": "1.99" }, "display_price": "$1.99", "multi_quantity": true, "owned": false } ],
"unfetched": [ { "id": "level_2", "reason": "not_found_or_not_on_sale" } ] }
- Without
ids, every product on sale. With them (up to 100), those on sale, and the rest inunfetched. owned(only for a person's token): a non-consumable they bought, or a consumable they bought and you haven't consumed yet. Such a product can't be bought again.- Show
display_price; never your own price list.
Start a purchase
curl https://gateway.nostrad.ai/v1/purchases -H "Authorization: Bearer $ACCESS_TOKEN" -H "content-type: application/json" \
-d '{"product": "coins_100", "quantity": 2, "account_token": "user-42", "return_url": "https://app.example/bought"}'
{ "purchase_url": "https://accounts.nostrad.ai/purchase/pur_...", "expires_at": 1793000000000 }
quantity: 1 to 10, only for a product with more than one in a purchase. Leave it out for 1.account_token(optional, Google's obfuscated account ID): your own ID for the person, up to 64 characters, never an email address. It comes back on the purchase and on orders.return_url(required): where the browser goes after Buy or Cancel. Nostrad sends it there only if, without its?query, it is one of your sign-in clients' return addresses (console, Sign in with Nostrad). Otherwise the page says the purchase is done and the person goes back to your app themselves.- Send the browser to
purchase_url. Only the person whose token started it can open it.expires_at(milliseconds since 1970) is 24 hours away; after that, start again. - Refused: 409
already_owned(callGET /v1/purchases), 404unavailable(not on sale, or the app isn't public and this person isn't a tester), 403billing_unavailable(their account can't buy now), 403needs_sign_in(an API key was sent).
Coming back
| The person chose | Your return_url gets |
|---|---|
| Buy | ?purchase_token=pt_... (added to any query it had) |
| Cancel | ?error=user_canceled |
The return alone proves nothing: anyone can open that address. Deliver only after your server has checked the purchase, or on the signed notification.
Restoring purchases
GET /v1/purchases with the person's token answers what they own in your app now: { "purchases": [ ... ] }, each shaped as above. Call it when they sign in on a new device, and after already_owned. Deliver, and acknowledge, any you haven't yet.