AutoPayCard API
Uzcard kartalar orqali avtomatik to'lov qabul qilish uchun tez va ishonchli API. Oson integratsiyasi orqali to'lovlar real vaqtda tasdiqlanadi.
Barcha so'rovlarda x-api-key headeri talab qilinadi. API kalitni @Autopaycardbot dan olishingiz mumkin.
x-api-key: sizning_api_kalitingiz
To'lov yaratishdan tasdiqlashgacha bo'lgan jarayon 5 bosqichdan iborat.
hisoblash
yaratish
kartaga o'tkazma
tekshirish
yuboriladi
Yangi to'lov yaratadi. Foydalanuvchiga aynan shu summani ko'rsating — u kartaga o'tkazadi.
| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
| amount | integer | Ha | Unikal summa (so'mda). Botingiz o'zi hisoblaydi: base + random(1,99) |
| card_last4 | string | Ha | Karta oxirgi 4 raqami. Masalan: "6412" |
| gmail | string | Ha | Karta ulangan Gmail manzil. Masalan: "user@gmail.com" |
| client_user_id | string | Yo'q | Foydalanuvchi ID (botingizdagi Telegram ID) |
| client_user_data | object | Yo'q | Qo'shimcha ma'lumotlar (JSON). Webhook da qaytariladi |
| webhook_url | string | Yo'q | To'lov tasdiqlanganda POST so'rov yuboriladi (HTTPS) |
import random, requests unique_amount = 50000 + random.randint(1, 99) # Unikal summa response = requests.post( "https://api.autopaycard.uz/api/create-payment", headers={"x-api-key": "sizning_kalitingiz"}, json={ "amount": unique_amount, "card_last4": "6412", "gmail": "karta@gmail.com", "client_user_id": "123456789", "client_user_data": {"plan": "premium"}, "webhook_url": "https://botingiz.uz/webhook", } ) data = response.json() order_id = data["order_id"] # Saqlang!
const uniqueAmount = 50000 + Math.floor(Math.random() * 99) + 1; const response = await fetch( "https://api.autopaycard.uz/api/create-payment", { method: "POST", headers: { "x-api-key": "sizning_kalitingiz", "Content-Type": "application/json" }, body: JSON.stringify({ amount: uniqueAmount, card_last4: "6412", gmail: "karta@gmail.com", client_user_id: "123456789", webhook_url: "https://botingiz.uz/webhook" }) } ); const { order_id } = await response.json();
{
"success": true,
"order_id": "10001" // Saqlang — webhook va tekshirishda kerak
}
Bekor qilingan statusga o'tadi.
card_last4 + gmail kombinatsiyasi @Autopaycardbot da ulangan bo'lishi shart. /api/my-cards orqali tekshiring.
To'lov holatini tekshiradi. Polling (har 5 soniyada tekshirish) yoki webhook orqali ishlatiladi.
| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
| order_id | string | Ha | create-payment dan kelgan order_id |
| Holat | Ma'no |
|---|---|
| waiting | To'lov kutilmoqda |
| paid | To'lov tasdiqlandi ✅ |
| expired | 5 daqiqa o'tdi, to'lov topilmadi |
import time, requests order_id = "10001" headers = {"x-api-key": "sizning_kalitingiz"} for _ in range(10): # 5 daqiqa (30 soniyada bir) r = requests.post( "https://api.autopaycard.uz/api/check-payment", headers=headers, json={"order_id": order_id} ).json() if r["status"] == "paid": print("✅ To'lov tasdiqlandi!") break elif r["status"] == "expired": print("❌ To'lov muddati o'tdi") break time.sleep(30)
{
"order_id": "10001",
"status": "paid",
"amount": 50037,
"card_last4": "6412",
"gmail": "karta@gmail.com",
"client_user_id": "123456789",
"client_user_data": {"plan": "premium"},
"paid_at": "2026-05-16 09:30:00"
}
Ulangan Uzcard kartalar ro'yxatini qaytaradi.
{
"cards": [
{
"id": 1,
"card_last4": "6412",
"gmail": "karta@gmail.com"
},
{
"id": 2,
"card_last4": "8675",
"gmail": "karta2@gmail.com"
}
]
}
Joriy obuna ma'lumotlarini qaytaradi.
{
"active": true,
"tariff_name": "Asosiy",
"expires_at": "2026-06-16 09:00:00",
"payments_used": 15,
"max_payments": 100000
}
Karta ulash uchun Gmail App parol kerak. Bu oddiy Gmail paroldan farqli — maxsus ilovalar uchun 16 belgili parol. Quyidagi bosqichlarni bajaring.
myaccount.google.com ga o'ting va Google hisobingizga kiringmyaccount.google.com/apppasswords kiriting va Enter bosingTo'lov tasdiqlanganda webhook_url ga avtomatik POST so'rov yuboriladi. Bu polling dan ko'ra yaxshiroq — real vaqtda bilish imkonini beradi.
{
"order_id": "10001",
"status": "paid",
"amount": 50037, // Aynan o'tkazilgan summa
"card_last4": "6412",
"gmail": "karta@gmail.com",
"client_user_id": "123456789", // Siz yuborgan ID
"client_user_data": {"plan": "premium"}, // Siz yuborgan data
"paid_at": "2026-05-16T09:30:00"
}
from fastapi import FastAPI, Request app = FastAPI() @app.post("/webhook") async def webhook(request: Request): data = await request.json() if data["status"] == "paid": order_id = data["order_id"] amount = data["amount"] user_id = data["client_user_id"] extra = data.get("client_user_data", {}) # Balansni to'ldirish yoki xizmat ko'rsatish await add_balance(user_id, amount) return {"ok": True}
@router.post("/webhook") async def payment_webhook(request: Request): data = await request.json() if data["status"] != "paid": return order_id = data["order_id"] amount = data["amount"] user_id = data["client_user_id"] # Siz yuborgan Telegram ID extra = data.get("client_user_data", {}) # Balans qo'shish await add_balance(user_id, amount) # Xabar yuborish await bot.send_message( user_id, f"✅ {amount:,} so'm hisobingizga tushdi!" ) return {"ok": True}
API standart HTTP status kodlarini qaytaradi.
| Kod | Sabab | Yechim |
|---|---|---|
| 401 | API kalit noto'g'ri yoki yo'q | x-api-key headerni tekshiring |
| 403 | Faol obuna yo'q yoki limit tugadi | @Autopaycardbot da obuna oling |
| 400 | Karta/gmail ulanmagan yoki parametr noto'g'ri | card_last4, gmail va amount ni tekshiring |
| 404 | To'lov topilmadi | order_id ni tekshiring |
| 429 | Rate limit — juda ko'p so'rov | Biroz kuting va qayta urinib ko'ring |
| 500 | Server xatosi | @Autopaycardbot ga xabar bering |
{
"detail": "Faol obuna yo'q! @Autopaycardbot da obuna oling."
}
Telegram bot uchun to'liq to'lov integratsiyasi misoli.
import random import aiohttp from aiogram import Bot, Dispatcher, F from aiogram.types import Message API_KEY = "sizning_kalitingiz" API_BASE = "https://api.autopaycard.uz" CARD_LAST4 = "6412" # @Autopaycardbot da ulangan karta GMAIL = "karta@gmail.com" # Karta ulangan Gmail # 1. To'lov yaratish async def create_payment(base_amount: int, user_id: int) -> dict: unique = base_amount + random.randint(1, 99) async with aiohttp.ClientSession() as session: resp = await session.post( f"{API_BASE}/api/create-payment", headers={"x-api-key": API_KEY}, json={ "amount": unique, "card_last4": CARD_LAST4, "gmail": GMAIL, "client_user_id": str(user_id), "webhook_url": "https://sizning-botingiz.uz/webhook", } ) data = await resp.json() data["unique_amount"] = unique return data # 2. Bot handler @dp.message(F.text == "💰 Balans to'ldirish") async def topup(msg: Message): result = await create_payment(50000, msg.from_user.id) if result.get("success"): unique = result["unique_amount"] await msg.answer( f"💳 To'lov yaratildi!\n\n" f"🏦 Kartaga: ***{CARD_LAST4}\n" f"💰 Summa: {unique:,} so'm\n" f"🆔 Order: {result['order_id']}\n\n" f"⏳ 5 daqiqa ichida o'tkazing!" ) # order_id ni DB ga saqlang await save_order(msg.from_user.id, result["order_id"], unique) # 3. Webhook qabul qilish @router.post("/webhook") async def webhook(request: Request): data = await request.json() if data["status"] == "paid": user_id = data["client_user_id"] amount = data["amount"] await add_balance(user_id, amount) await bot.send_message(user_id, f"✅ {amount:,} so'm qabul qilindi!") return {"ok": True}