Your server
Your server: check, acknowledge, consume
curl https://gateway.nostrad.ai/v1/purchases/$PURCHASE_TOKEN -H "Authorization: Bearer $SALES_KEY"
{ "purchase_token": "pt_...", "order_id": "NOS.1234-5678-9012-34567", "product": "coins_100", "type": "consumable",
"quantity": 2, "refundable_quantity": 2, "state": "purchased", "acknowledgement": "pending", "consumption": "not_consumed",
"account_token": "user-42", "purchased_at": 1793000000000, "price": { "credits": 398, "usd": "$3.98" },
"refunded": 0, "test": false, "acknowledge_by": 1793259200000 }
| Field | Meaning |
|---|---|
state | purchased, or cancelled once it was refunded and taken back: take away what you gave |
acknowledgement | pending until you acknowledge or consume it; acknowledged after |
consumption | Consumables only: not_consumed or consumed |
acknowledge_by | When it is refunded unless acknowledged (milliseconds); null once acknowledged |
refunded, refundable_quantity | Credits refunded so far, and how many of the quantity can still be refunded |
test | A test purchase: no credit moved |
POST /v1/purchases/<token>/acknowledgeandPOST /v1/purchases/<token>/consumeanswer the purchase. Consume acknowledges too; only a consumable can be consumed. Acknowledging twice changes nothing. Acknowledging a consumed purchase answers 400invalid_purchase_state, and consuming one again answers 409not_owned: if you were retrying andGET /v1/purchases/<token>says it's consumed, you can ignore that error.- A token that isn't this app's, or a purchase taken back, answers 409
not_owned. - Keep the purchase token with what you delivered, so the same token never delivers twice.
Orders
The order ID (NOS.1234-5678-9012-34567) is what the buyer sees on the receipt Nostrad emails them and under Purchases on their account; ask for it when they write to you.
GET /v1/orders/<order_id>: one order: the purchase as above, withorder_state(processed,partially_refundedorrefunded) and itsrefunds(eachamount,quantity,refund_type,revoke,source,at).GET /v1/orders: newest first, 20 a page, byproduct,type,refunded(trueorfalse),account_token,startandend(milliseconds),sort=ascending, andcursorfromnext_cursor.
Security
- Keep the Sales key on your server only, never in your app or a web page.
- Coming back to your
return_urlproves nothing: anyone can open that address. Deliver only after your server has checked the purchase, or on the signed notification. - Check each notification's signature before you act on it: Notifications reference.
- Keep the purchase token with what you delivered, so the same token never delivers twice.
- Use
account_tokento tie a purchase to the person in your own system. It is never an email address or anything that names the person.