Store API¶
This api allows to buy TU contracts and other downloadable items.
Common response¶
Error¶
{ status: "error", code: "some_error_code", text: "error_text" }
Succeess response¶
{ status: "OK", <any specific data> }
Common structures¶
ProductRecord¶
descripbes some product being sold by the URS as a whole.
{ "productCode": string, "name": string, "description": "htmlString", prices: [PriceRecord] }
depending on the product type there might be additional fields, like, for transaction packs, as in the sample:
{
"productId" : "1",
"name" : "Uno Universa Package",
"description" : "4 transaction on main net / 10k test transactions / 1 year of access",
"prices" : [ {
"currency" : "UTNP",
"amount" : "1"
} ],
"tuCount" : 4,
"testTuCount" : 10000,
"durationInMonth" : 12
}
OrderItemRecord¶
Much like ProductRecord, but describes a product in the order
{"productCode":string,"quantity":1,"currency":"UTNP","amount":decimalString}
PriceRecord¶
Descrubes some price that URS accepts. As URS can take more than one type of currency, there could be several such records. As for now the only currency type allowed is UTNP, for example:
{ currency: "UTNP", amount: "0.01" }
Make sure you always process amounts as strings when encoding/decoding from/to JSON and like formats and use something like BigDecimal (not flouat or double) in calculations. It is very important.
OrderStateRecord¶
The records describes the state of some record. The structire with following fields:
{
orderCode: string,
products: [OrderItemRecord],// what is being purchased
price: PriceRecord, // what paymnent is expected
paymentAddress: string, // to which address the payment should be sent to
status: string, // state, see below
statusNote: string, // some explanation of the current state in a form readable by the end user
validUntil: UnixTime, // the latest instant until then the payment will be accepted in seconds since unix epoch, UTC.
returnAddress: String // address to return the funds on error or cancel]
}
status values are:
awaits_payment: the order is waiting for the paymentin_progress: the payment is received in time and accepted, the order is being executed.ready: the order is processed and the results can be loadedreturning_payment: the order is being refundedcancelled: the order is cancelled, payments were returned (if any)
UnixTime¶
Integer number of seconds from the unix epoch (Jan 1, 1970, UTC) to some instant. Could be positive or negative. The instant of time is supposed to be in UTC (e.g. GMT + 00:00).
List avaialable products¶
GET /api/v1/products/list?filter=tu
Filter is optional, this one let exclude products that are not TU packs. Shown only as a sample
Success
{ products: [ProductRecord] }
Here is an example:
{ status: "OK", products: [
{
productId: "Minimal 10TU pack"
description: "This is a minimal pack of TUs that gives 10TUs on mainnet and 10000TUs on testnet and a year of a basic service with cryptocloud."
prices: [ { currencty: "UTNP", amount: "1.0" }]
}
]}
Order some product¶
Attention! This is a temporary API that will be changed very soon with signed request block! It is for the first stage only.
POST /api/v1/products/order
With parameters:
productCode: string as in the
ProductRecordcurrency: string - which currency user intends to pay with
quantity: integer, defaults to 1
publicKey: string, base64-encoded binary packed public key in the universa format.
returnAddress: string, the address to return funds in the case of errors or refund.
promoCode: opt string: some promotional code could be discount or some bonus
Note that the purchased product will only be usable with a public key provided. Be careful as we are not providing returning service at the moment.
Success response:
``js
{ orderState: OrderStateRecord }
## Check the order state
GET /api/v1/products/orders/<orderCode>/state
With parameteds:
- orderCode: string as in the `OrderStateRecord`
Returns:
```js
{ orderState: OrderStateRecord }
download the ready order¶
GET /api/v1/products/orders/<orderCode>
If the order state is ready this call returns the purchazed items in the following form:
{ purchasedProducts: [
productCode: string, // as in the OrderStateRecord.products[]
base64: string // base64-encoded binary for the product
]}
Note that if several prducts of the same type, hence the same productCode, the system will produce the corresponding number of recirds in purchasedProducts.
Helpers¶
Get the contract cost and testnet compatibility¶
POST /api/v1/contracts/cost
with parameter
packedContract: contract to check, full packed (as transaction pack) in base64 form.
Note that partially packed contract will not be processed in a correct manner. The result will be like:
{
"costInTu" : <int>,
"testnetCompatible" : true|false,
}