Selling inside your app
Sell things inside your app, such as coins, a level, a feature or a subscription, to people who signed in to it with Nostrad. They pay from their Nostrad credit on a Nostrad page, and Nostrad tells your server. It works like Google Play Billing and Apple's In-App Purchase: the same steps, the same rules, and the same names where it can. All of it goes through the Nostrad gateway at https://gateway.nostrad.ai. Back to the documentation.
The API definition is in openapi.json (OpenAPI 3.1).
How a purchase works
- Your app lists what's on sale:
GET /v1/products. - The person chooses something. Your server starts the purchase with their sign-in token:
POST /v1/purchases. It answers apurchase_urlonhttps://accounts.nostrad.ai. - Send their browser there. Nostrad shows what it is, the price, their balance and their balance after, and Buy or Cancel. The page lasts 24 hours.
- They choose Buy. The price is taken from their credit; you get 70% of it and Nostrad keeps 30%. Nostrad sends their browser back to your
return_urlwithpurchase_tokenadded, and sends your server a signedONE_TIME_PRODUCT_PURCHASEDnotification. - Your server checks the purchase with your app's API key:
GET /v1/purchases/<token>. It delivers what was bought, then acknowledges it:POST /v1/purchases/<token>/acknowledge. A consumable can instead be consumed (POST /v1/purchases/<token>/consume), which acknowledges it and lets it be bought again. - A purchase not acknowledged within 3 days is refunded in full and taken back. Acknowledge only after you deliver.
Two kinds of caller, as on Google Play:
| Who calls | With | Commands |
|---|---|---|
| Your app, for the signed-in person | Their Sign in with Nostrad access token | GET /v1/products, POST /v1/purchases, GET /v1/purchases |
| Your server | An API key of this app with Sales ticked | Everything else: checking, acknowledging, consuming, orders, refunds, notifications. A key without Sales answers 403 sales_permission_needed |
GET /v1/products takes either; with an API key it lists the products without owned.
Terms
| Term | What it means |
|---|---|
| Product | What you sell: consumable, non_consumable or subscription |
| Purchase token | pt_...: names one purchase. A subscription keeps its token across renewals |
| Order ID | NOS.1234-5678-9012-34567: names one charge. The buyer sees it on their receipt. Each subscription renewal is a new order |
| Acknowledge | Your server telling Nostrad it delivered what was bought |
| Consume | Your server telling Nostrad a consumable was used up, so it can be bought again |
| Revoke | Taking back what was bought, with or without a refund |
| Sales key | An API key of your app with Sales ticked, kept on your server |
| License tester | A Nostrad account whose purchases in your app are test purchases |
| Credit | What buyers pay with: 1 credit is 1 US cent |