StarPay API Documentation
StarPay - cryptoacquiring, which allows you to issue invoices and receive payment in cryptocurrency for selling services or goods on its platform. Below are the methods for creating invoices and others.
StarPay API Authorization
All methods require 2 mandatory arguments (Api Id and Api Key), transmitted in the header of the https request. Which you can get by creating your new merchant in the telegram bot @StarWalletBot. After creating a merchant, you will be given secret data, keep this data in a safe place. Use them to authorize in the StarPay Api. All requests to the Api must be performed via the HTTPS protocol.
Webhook API StarPay
Get instant notifications about invoice status changes or get the status via GET invoicestatus method. As soon as the invoice status changes, we will send an HTTPS POST request notification to your Webhook URL specified when creating the merchant until we receive a 200 response, but no more than 3 times, with a period of 5 minutes.
You can verify the received update by comparing the starpay-api-signature header parameter with the received response. To do this, sort the received JSON response by keys and convert it to a string, for example using JSON.stringify. Next, sign the string with the Webhook Secret Key using HMAC and the sha-512 key. Then compare the signed string from the previous step with the starpay-api-signature string stored in the request header, if these strings match, then everything is fine.
Below is an example of creating a signature string in Python.
import json
import hmac
import hashlib
def s_signature_check(webhook_secret_key, starpay-api-signature, message):
sorted_msg = json.dumps(message, separators=(',', ':'), sort_keys=True)
digest = hmac.new(
str(webhook_secret_key).encode(),
f'{sorted_msg}'.encode(),
hashlib.sha512)
signature = digest.hexdigest()
if signature == starpay-api-signature:
return
else:
print("HMAC signature does not match")
Below is an example of creating a subscription string in PHP.
function tksort(&$array)
{
ksort($array);
foreach(array_keys($array) as $k)
{
if(gettype($array[$k])=="array")
{
tksort($array[$k]);
}
}
}
function check_ipn_request_is_valid()
{
$error_msg = "Unknown error";
$auth_ok = false;
$request_data = null;
if (isset($_SERVER['starpay-api-signature']) && !empty($_SERVER['starpay-api-signature'])) {
$recived_hmac = $_SERVER['starpay-api-signature'];
$request_json = file_get_contents('php://input');
$request_data = json_decode($request_json, true);
tksort($request_data);
$sorted_request_json = json_encode($request_data, JSON_UNESCAPED_SLASHES);
if ($request_json !== false && !empty($request_json)) {
$hmac = hash_hmac("sha512", $sorted_request_json, trim($this->ipn_secret));
if ($hmac == $recived_hmac) {
$auth_ok = true;
} else {
$error_msg = 'HMAC signature does not match';
}
} else {
$error_msg = 'Error reading POST data';
}
} else {
$error_msg = 'No HMAC signature sent.';
}
}
Below is an example of creating a subscription string in Node JS.
function sortObject(obj) {
return Object.keys(obj).sort().reduce(
(result, key) => {
result[key] = (obj[key] && typeof obj[key] === 'object') ? sortObject(obj[key]) : obj[key]
return result
},
{}
)
}
const hmac = crypto.createHmac('sha512', notificationsKey);
hmac.update(JSON.stringify(sortObject(params)));
const signature = hmac.digest('hex');
StarPay API Methods
https://starwallet.tech/api/v1/post/createdinvoice/
Headers
s-api-id:
Api Id of your merchant.
s-api-key:
Your merchant's API Key.
Content-Type:
application/json
Response
error_status:
(Boolean) Error status.
error_text:
(String) Error text.
invoice_id:
(String) Unique invoice id.
created_at:
(String) Date of creation in ISO 8601.
invoice_summa:
(Float) Invoice amount in USD.
invoice_description:
(String) Description.
invoice_paid:
(Boolean) Invoice payment status.
invoice_url:
(String) Link to pay invoice.
Json:
{
"error_status": false,
"error_text": "",
"result": {
"invoice_id": "5924374364",
"created_at": "2024-10-30T14:15:54.118068",
"invoice_summa": 45.15,
"invoice_description": "45",
"invoice_paid": false
}
}
Json:
{"error_status":true,"error_text":"The data is not valid"}
Json:
{"error_status":true,"error_text":"'invoice_value' must be between 1 and 100000"}
https://starwallet.tech/api/v1/get/invoicestatus/{invoice_id}
{invoice_id}:
Unique invoice identifier.
Headers
s-api-id:
Api Id of your merchant.
s-api-key:
Your merchant's API Key.
Response
error_status:
(Boolean) Error status.
error_text:
(String) Error text.
invoice_id:
(String) Unique invoice id.
created_at:
(String) Date of creation in ISO 8601.
invoice_summa:
(Float) Invoice amount in USD.
invoice_description:
(String) Description.
invoice_paid:
(Boolean) Invoice payment status.
invoice_url:
(String) Link to pay invoice.
Json:
{"error_status":false,"error_text":"","result":{"invoice_id":"000000000000","created_at":"2024-00-00T00:00:00.000000","invoice_summa":00.00,"invoice_description":"description","invoice_paid":false,"invoice_url":"https://starwallet.tech/invoice/000000000000/ru"}}
Json:
{"error_status":true,"error_text":"The data is not valid"}
Json:
{"error_status":true,"error_text":"Invoice not found"}