PayStars একীভূত API · v3.0
একটি API.
StarKerak-এর মতো একই ব্যালেন্স।
ওয়েবসাইট, Telegram WebApp ও বাহ্যিক API সবই একই StarKerak ব্যালেন্স ও অর্ডার-পূরণ ইঞ্জিন ব্যবহার করে। API কী-এর অর্ডারে Fragment মূল্য অতিরিক্ত মার্কআপ ছাড়া পরিশোধ হয়। API প্রতিক্রিয়া JSON আকারে আসে।
প্রমাণীকরণ
ড্যাশবোর্ডে একটি API কী তৈরি করুন। সম্পূর্ণ কী শুধু একবার দেখানো হয়। এটি আপনার সার্ভার পরিবেশে রাখুন; কখনও ফ্রন্টএন্ড JavaScript বা Git রিপোজিটরিতে রাখবেন না।
X-API-Key: ps_your_secret_api_key Content-Type: application/json Idempotency-Key: order_20260719_0001
সীমা, যাচাইকরণ ও আইডেমপোটেন্সি
- প্রতি API কী-তে প্রতি সেকেন্ডে 10টি অনুরোধ।
- API-এর মাধ্যমে প্রাপক যাচাইয়ের সীমা: প্রতি অ্যাকাউন্টে প্রতি মিনিটে 120; ওয়েবসাইট/WebApp-এর জন্য 12।
- কেনার আগে আপনাকে
/check-usernameকল করতে হবে এবং 180 সেকেন্ডের জন্য বৈধ একটিverification_tokenপেতে হবে। - প্রতিটি যাচাইকরণ টোকেন ঠিক একটি যৌক্তিক অর্ডারের সাথে বাঁধা; একই আইডেমপোটেন্সি কী দিয়ে নিরাপদে পুনরায় চেষ্টা সমর্থিত।
- Stars ও Premium কেনাকাটায় একটি অনন্য 8–128 অক্ষরের
Idempotency-Keyপাঠান। - একই পেলোডসহ একই
Idempotency-Keyআবার পাঠালে পুনরায় চার্জ হয় না; মূল অর্ডার ফেরত দেওয়া হয়। - ভিন্ন পেলোডসহ একটি আইডেমপোটেন্সি কী পুনরায় ব্যবহার করলে
409 Conflictফেরত আসে।
API স্ট্যাটাস
/statuscurl https://paystars.uz/api/v1/status
USD ব্যালেন্স ও মূল্য
অ্যাকাউন্ট ও ডলার ব্যালেন্স StarKerak থেকে আসে। মূল্য USD-তে: API কী দিয়ে দেওয়া প্রতিটি অর্ডারের খরচ সরাসরি Fragment মূল্য, মার্কআপ ছাড়া (সব বিদ্যমান কীসহ)।
/accountcurl https://paystars.uz/api/v1/account \
-H "X-API-Key: $PAYSTARS_API_KEY"{
"ok": true,
"user": { "telegram_id": 123456789 },
"balances": { "USD": "12.50" },
"currency_pref": "USD"
}/pricesUSD মূল্যের জন্য POST /usd/quote ব্যবহার করুন (নিচে): API কীসহ, মূল্য = Fragment মূল্য (মার্কআপ ছাড়া)।
ইউজারনেম যাচাই
এই এন্ডপয়েন্ট নাম, ছবি ও Premium স্ট্যাটাস নির্ণয় করতে Fragment ব্যবহার করে। verification_token শুধু সেই প্রাপকের জন্য ফেরত দেওয়া হয় যার জন্য কেনা যায়।
/check-usernamecurl -X POST https://paystars.uz/api/v1/check-username \ -H "X-API-Key: $PAYSTARS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"username":"telegram","kind":"premium"}'
{
"valid": true,
"username": "telegram",
"nickname": "Telegram User",
"photo_url": "https://cdn4.telesco.pe/...",
"premium_active": false,
"verification_token": "...",
"verification_expires_in": 180
}kind হলো stars বা premium। Premium ইতিমধ্যে সক্রিয় থাকলে আপনি পাবেন premium_active: true, valid: false এবং একটি null টোকেন।
Stars অর্ডার
/stars/buycurl -X POST https://paystars.uz/api/v1/stars/buy \ -H "X-API-Key: $PAYSTARS_API_KEY" \ -H "Idempotency-Key: order_20260719_0001" \ -H "Content-Type: application/json" \ -d '{"username":"telegram","quantity":100,"verification_token":"TOKEN_FROM_CHECK","currency":"USD","max_usd":1.50}'
{
"ok": true,
"order_id": 1842,
"status": "processing",
"quantity": 100,
"cost": 1.50,
"balance": 10.92,
"currency": "USD"
}ডলার (USD) ব্যালেন্স ও USDT
API পেমেন্ট ডলার ব্যালেন্স থেকে করা হয়। এটি TON, BEP20 বা TRC20 নেটওয়ার্কে USDT দিয়ে টপ আপ করা হয় (সর্বনিম্ন 0.1 USDT)। API কী-এর মাধ্যমে USD মূল্য = Fragment মূল্য, মার্কআপ ছাড়া (সেন্ট পর্যন্ত উপরের দিকে পূর্ণ করা)।
/usd/walletডলার ব্যালেন্স, TON ঠিকানা ও ব্যক্তিগত মেমো, BEP20 ঠিকানা (QR ছবিসহ)।
{
"ok": true,
"usd": { "balance": "12.50", "micros": 12500000 },
"min_deposit": "1.00",
"ton": { "address": "UQ...", "memo": "...", "enabled": true, "ttl_min": 30 },
"bsc": { "address": "0x...", "contract": "0x55d398326f99059fF775485246999027B3197955", "enabled": true, "ttl_min": 30 }
}usd.balance হলো ডলার ব্যালেন্স (স্ট্রিং); usd.micros: 1 USD = 1,000,000 মাইক্রো।
/usd/invoice{"amount": 10, "chain": "ton"} বা "chain": "bsc" → 30 মিনিটের জন্য বৈধ একটি সঠিক পরিমাণ (যেমন 10.0437)। নির্বাচিত নেটওয়ার্কের ঠিকানায় ঠিক সেই পরিমাণ USDT পাঠান (TON-এর জন্য মেমো লাগে না)। /usd/bsc-invoice এখনও একটি লিগ্যাসি উপনাম হিসেবে কাজ করে (ডিফল্ট: bsc)।
/usd/invoice/{id}/cancelএকটি অপেক্ষমাণ ইনভয়েস বাতিল করে (যেমন পরিমাণ বদলাতে)। বাতিল করা সঠিক পরিমাণ 24 ঘণ্টার জন্য অন্য কাউকে দেওয়া হয় না, এবং সেই সময়ের মধ্যে আসা পেমেন্ট এখনও আপনার ব্যালেন্সে জমা হয়।
/usd/invoice/{id}স্ট্যাটাস: pending, paid, expired বা cancelled।
/usd/quote{"kind":"stars","username":"durov","quantity":100} বা {"kind":"premium","username":"durov","months":3} → {"usd": 1.50}।
ডলার ব্যালেন্স থেকে পরিশোধ করতে /usd/quote থেকে "currency": "USD" ও "max_usd": 1.50 /stars/buy বা /premium/buy পেলোডে যোগ করুন। Fragment মূল্য max_usd ছাড়িয়ে গেলে কিছুই চার্জ হয় না এবং 409 price_changed ফেরত আসে — নতুন কোট নিন। currency বাদ দিলে অ্যাকাউন্টের সংরক্ষিত মুদ্রা পছন্দ (/usd/wallet-এ pref) ব্যবহার হয় — তাই সবসময় "currency": "USD" পাঠান। প্রতিক্রিয়ায় cost ও balance currency ফিল্ডে দেওয়া মুদ্রায় থাকে।
curl -X POST https://paystars.uz/api/v1/stars/buy \
-H "X-API-Key: $PAYSTARS_API_KEY" -H "Idempotency-Key: stars_8f2c1a9b" \
-H "Content-Type: application/json" \
-d '{"username":"durov","quantity":100,"verification_token":"...","currency":"USD","max_usd":1.50}'অর্ডার
/ordersওয়েবসাইট, WebApp ও API-এর মাধ্যমে দেওয়া সর্বশেষ 50টি অর্ডার ফেরত দেয়।
/order/{order_id}curl https://paystars.uz/api/v1/order/1842 \
-H "X-API-Key: $PAYSTARS_API_KEY"ত্রুটি
| স্ট্যাটাস | অর্থ | কী করবেন |
|---|---|---|
| 400 | অবৈধ পেলোড বা আইডেমপোটেন্সি কী | অনুরোধের ফরম্যাট যাচাই করুন |
| 401 | অবৈধ API কী | নতুন কী তৈরি করুন |
| 402 | অপর্যাপ্ত USD ব্যালেন্স | USDT দিয়ে টপ আপ করুন |
| 409 | যাচাইকরণের মেয়াদ শেষ/ব্যবহৃত অথবা আইডেমপোটেন্সি সংঘাত | প্রাপককে আবার যাচাই করুন |
| 422 | ইউজারনেম বা সেবা অনুপলব্ধ | প্রাপক যাচাই করুন |
| 402 | insufficient_balance (USD) | USDT দিয়ে ডলার ব্যালেন্স টপ আপ করুন |
| 409 | price_changed — USD মূল্য max_usd ছাড়িয়ে গেছে | নতুন /usd/quote নিন |
| 429 | রেট সীমা অতিক্রম হয়েছে | Retry-After-এর পরে আবার চেষ্টা করুন |
| 503 | সেবা সাময়িকভাবে অনুপলব্ধ | এক্সপোনেনশিয়াল ব্যাকঅফ ব্যবহার করুন |
{
"detail": {
"code": "insufficient_balance",
"message": "StarKerak balance is insufficient"
}
}কার্যকর উদাহরণ
বিভিন্ন প্রোগ্রামিং ভাষায়
প্রতিটি উদাহরণ প্রাপক যাচাই করে, স্বল্পমেয়াদি টোকেন নেয় এবং একটি আইডেমপোটেন্সি কী ব্যবহার করে যাতে একই অর্ডার নিরাপদে আবার চেষ্টা করা যায়।
API="https://paystars.uz/api/v1"
ORDER_KEY="stars_$(uuidgen)"
VERIFY=$(curl --fail-with-body -sS -X POST "$API/check-username" \
-H "X-API-Key: $PAYSTARS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"username":"telegram","kind":"stars"}')
TOKEN=$(printf '%s' "$VERIFY" | jq -r '.verification_token')
curl --fail-with-body -sS -X POST "$API/stars/buy" \
-H "X-API-Key: $PAYSTARS_API_KEY" \
-H "Idempotency-Key: $ORDER_KEY" \
-H "Content-Type: application/json" \
-d "{\"username\":\"telegram\",\"quantity\":100,\"verification_token\":\"$TOKEN\",\"currency\":\"USD\"}"import { randomUUID } from 'node:crypto';
const base = 'https://paystars.uz/api/v1';
const headers = { 'X-API-Key': process.env.PAYSTARS_API_KEY, 'Content-Type': 'application/json' };
const verify = await fetch(`${base}/check-username`, {
method: 'POST', headers, body: JSON.stringify({ username: 'telegram', kind: 'stars' })
}).then(async r => { if (!r.ok) throw new Error(await r.text()); return r.json(); });
const order = await fetch(`${base}/stars/buy`, {
method: 'POST', headers: { ...headers, 'Idempotency-Key': `stars_${randomUUID()}` },
body: JSON.stringify({ username: verify.username, quantity: 100, verification_token: verify.verification_token, currency: 'USD' })
}).then(async r => { if (!r.ok) throw new Error(await r.text()); return r.json(); });
console.log(order.order_id, order.status);import os, uuid, requests
base = "https://paystars.uz/api/v1"
headers = {"X-API-Key": os.environ["PAYSTARS_API_KEY"]}
verify = requests.post(f"{base}/check-username", headers=headers,
json={"username": "telegram", "kind": "premium"}, timeout=15)
verify.raise_for_status()
recipient = verify.json()
order = requests.post(f"{base}/premium/buy", headers={
**headers, "Idempotency-Key": f"premium_{uuid.uuid4()}"
}, json={"username": recipient["username"], "months": 3,
"verification_token": recipient["verification_token"], "currency": "USD"}, timeout=20)
order.raise_for_status()
print(order.json())<?php
$base = 'https://paystars.uz/api/v1';
$key = getenv('PAYSTARS_API_KEY');
function postJson($url, $headers, $body) {
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_HTTPHEADER => $headers, CURLOPT_POSTFIELDS => json_encode($body), CURLOPT_TIMEOUT => 20]);
$raw = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
if ($status < 200 || $status >= 300) throw new RuntimeException($raw);
return json_decode($raw, true, flags: JSON_THROW_ON_ERROR);
}
$common = ["X-API-Key: $key", 'Content-Type: application/json'];
$user = postJson("$base/check-username", $common, ['username' => 'telegram', 'kind' => 'stars']);
$order = postJson("$base/stars/buy", [...$common, 'Idempotency-Key: stars_'.bin2hex(random_bytes(16))],
['username' => $user['username'], 'quantity' => 100, 'verification_token' => $user['verification_token'], 'currency' => 'USD']);
print_r($order);package main
import ("bytes"; "encoding/json"; "fmt"; "io"; "net/http"; "os"; "github.com/google/uuid")
func post(path string, body any, idempotency string, out any) error {
data, _ := json.Marshal(body)
req, _ := http.NewRequest("POST", "https://paystars.uz/api/v1"+path, bytes.NewReader(data))
req.Header.Set("X-API-Key", os.Getenv("PAYSTARS_API_KEY")); req.Header.Set("Content-Type", "application/json")
if idempotency != "" { req.Header.Set("Idempotency-Key", idempotency) }
res, err := http.DefaultClient.Do(req); if err != nil { return err }; defer res.Body.Close()
if res.StatusCode >= 300 { raw, _ := io.ReadAll(res.Body); return fmt.Errorf("API %d: %s", res.StatusCode, raw) }
return json.NewDecoder(res.Body).Decode(out)
}
func main() {
var user struct { Username string `json:"username"`; VerificationToken string `json:"verification_token"` }
if err := post("/check-username", map[string]any{"username":"telegram", "kind":"stars"}, "", &user); err != nil { panic(err) }
var order map[string]any
if err := post("/stars/buy", map[string]any{"username":user.Username, "quantity":100,
"verification_token":user.VerificationToken, "currency":"USD"}, "stars_"+uuid.NewString(), &order); err != nil { panic(err) }
fmt.Println(order)
}একটি প্রম্পট দিয়ে ইন্টিগ্রেট করুন
AI প্রম্পট
এই প্রম্পট Codex, ChatGPT বা অন্য কোনো কোডিং এজেন্টকে পাঠান। আপনার প্রকল্পের সাথে মেলাতে বন্ধনীর মানগুলো বদলান।
You are a senior backend and application-security engineer. Build me a complete, production-ready integration with the PayStars API.
PROJECT TYPE: [Telegram bot / web backend / mobile app backend]
LANGUAGE AND FRAMEWORK: [e.g. Python 3.12 + aiogram 3 + FastAPI]
PROJECT NAME: [name]
PayStars base URL: https://paystars.uz/api/v1
Read the API key only from the PAYSTARS_API_KEY environment variable. Never expose it to the frontend, logs, Git or error messages. All requests must be HTTPS and server-side. Add timeouts, structured logging (without secrets), input validation and tests.
Implement the following flow completely:
1. Get the USD balance via GET /usd/wallet. Do not hardcode prices: before every purchase get the USD price via POST /usd/quote (with an API key: 0% (Fragment price); website: 5%).
2. Before a Stars or Premium purchase, send {"username":"...","kind":"stars|premium"} to POST /check-username.
3. Check valid, nickname, photo_url, premium_active and verification_token in the response. Show the user the photo, name, @username and Premium status and get explicit confirmation. Do not create an order without confirmation.
4. verification_token is valid for 180 seconds. If it expires or a 409 is returned, re-check the username.
5. For Stars send username, quantity and verification_token to POST /stars/buy; for Premium send username, months (3, 6 or 12) and verification_token to POST /premium/buy. In every purchase send "currency": "USD" and the quoted price as "max_usd"; on 409 price_changed fetch a new quote, on 402 insufficient_balance ask the user to top up the USD balance with USDT (TON, BEP20 or TRC20).
6. For each logical order generate an 8–128 character Idempotency-Key based on a cryptographic UUID. On network retries reuse exactly the same key and payload; never reuse it for another order.
7. Poll status via GET /order/{order_id} and show history via GET /orders. Handle processing/pending/completed/failed states correctly.
8. The API limit is 10 requests per second per key. On 429 honour Retry-After; on 503 and transient network errors use bounded exponential backoff with jitter. Give the user a safe, clear message for 400, 401, 402, 409, 422, 429 and 503.
9. Do not trust API responses blindly: validate against a schema, normalise usernames, enforce quantity/months limits server-side. Display photo_url only as an allowed HTTPS image. Never log the verification token, API key or full request headers.
10. Handle concurrent clicks by the same user, replay, duplicate orders, forged callbacks, race conditions, timeouts and process restarts. Persist state in the database with transactions and bind the user's confirmation to the order.
If the project is a Telegram bot: create /start, "Buy Stars", "Buy Premium", "Balance", "Orders" menus; collect the username and amount step by step; after the check show inline "Confirm/Cancel" buttons; verify callback ownership and TTL; secure the webhook secret or long-polling setup.
Deliver real, runnable code, not pseudo-code: exact folder structure, dependency file, .env.example (no real secrets), database migrations, Dockerfile, healthcheck, README, local run and deploy instructions, unit/integration tests. Put the API client in a separate module. Treat the PayStars API as the single source of truth for all prices, balances and orders; never connect to the StarKerak database directly. First ask for any missing business values as a short list, and make the remaining technical decisions yourself with safe defaults.