starkerak 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- starkerak-0.1.0/PKG-INFO +15 -0
- starkerak-0.1.0/README.md +66 -0
- starkerak-0.1.0/setup.cfg +4 -0
- starkerak-0.1.0/setup.py +19 -0
- starkerak-0.1.0/starkerak.egg-info/PKG-INFO +15 -0
- starkerak-0.1.0/starkerak.egg-info/SOURCES.txt +8 -0
- starkerak-0.1.0/starkerak.egg-info/dependency_links.txt +1 -0
- starkerak-0.1.0/starkerak.egg-info/requires.txt +1 -0
- starkerak-0.1.0/starkerak.egg-info/top_level.txt +1 -0
- starkerak-0.1.0/starkerak.py +72 -0
starkerak-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: starkerak
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: StarKerak To'lov Monitoring API va Websocket Client
|
|
5
|
+
Author: StarKerak Jamoasi
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: classifier
|
|
13
|
+
Dynamic: requires-dist
|
|
14
|
+
Dynamic: requires-python
|
|
15
|
+
Dynamic: summary
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# StarKerak Python SDK
|
|
2
|
+
|
|
3
|
+
StarKerak xizmatining rasmiy Python kutubxonasi. Bu kutubxona orqali siz o'zingizning domensiz (VPS) ishlayotgan Python botlaringizga to'lov ma'lumotlarini (Telegramdan tushgan SMS cheklarni) Real-Time (Websocket) yordamida qabul qila olasiz.
|
|
4
|
+
|
|
5
|
+
## O'rnatish
|
|
6
|
+
|
|
7
|
+
Kutubxonani loyihangizga qo'shish uchun quyidagi buyruqni ishlating:
|
|
8
|
+
```bash
|
|
9
|
+
pip install starkerak
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Foydalanish (Sinxron oddiy usul)
|
|
13
|
+
Kodni alohida script tarzida yurgizish uchun:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from starkerak import StarKerakClient
|
|
17
|
+
|
|
18
|
+
# WebApp dagi "Sozlamalar" bo'limidan olingan API kalitni kiriting
|
|
19
|
+
client = StarKerakClient("API_KALITINGIZ_SHU_YERDA")
|
|
20
|
+
|
|
21
|
+
@client.on_payment
|
|
22
|
+
def tolov_kelganda(payment):
|
|
23
|
+
# To'lov ma'lumotlari JSON shaklida keladi
|
|
24
|
+
print(f"🎉 Pul tushdi! {payment['amount']} UZS")
|
|
25
|
+
print(f"Karta: {payment['card_last4']}")
|
|
26
|
+
# Bu yerda foydalanuvchiga VIP maqomini berish yoki xizmatni yoqish kodingizni yozing
|
|
27
|
+
|
|
28
|
+
# Kutishni boshlash (bu kod scriptni kutish rejimiga o'tkazadi)
|
|
29
|
+
client.start_listening()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Foydalanish (Asinxron - Aiogram bot bilan)
|
|
33
|
+
Agar sizda Aiogram bot bo'lsa va bot bilan birga parallel ishlashini xohlasangiz:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import asyncio
|
|
37
|
+
from aiogram import Bot, Dispatcher
|
|
38
|
+
from starkerak import StarKerakClient
|
|
39
|
+
|
|
40
|
+
bot = Bot(token="Sizning_Bot_Tokeningiz")
|
|
41
|
+
dp = Dispatcher()
|
|
42
|
+
|
|
43
|
+
# StarKerak ulanishi
|
|
44
|
+
sk_client = StarKerakClient("API_KALITINGIZ_SHU_YERDA")
|
|
45
|
+
|
|
46
|
+
@sk_client.on_payment
|
|
47
|
+
async def tolov_kelganda(payment):
|
|
48
|
+
print("Pul tushdi!", payment)
|
|
49
|
+
# Masalan foydalanuvchiga xabar yuborish:
|
|
50
|
+
# await bot.send_message(foydalanuvchi_id, f"Sizdan {payment['amount']} UZS to'lov olinib, VIP yoqildi!")
|
|
51
|
+
|
|
52
|
+
async def main():
|
|
53
|
+
# Ham botni, ham StarKerakni parallel ishga tushirish
|
|
54
|
+
await asyncio.gather(
|
|
55
|
+
dp.start_polling(bot),
|
|
56
|
+
sk_client.start_listening_async()
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
asyncio.run(main())
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Afzalliklari
|
|
64
|
+
- **0.1 soniyada** kelib tushadi (Websocket texnologiyasi asosida)
|
|
65
|
+
- Hech qanday Domen, Hosting yoki HTTPS SSL sertifikatlarni talab qilmaydi
|
|
66
|
+
- Serveringizga ortiqcha bosim tushmaydi.
|
starkerak-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="starkerak",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="StarKerak To'lov Monitoring API va Websocket Client",
|
|
7
|
+
author="StarKerak Jamoasi",
|
|
8
|
+
packages=find_packages(),
|
|
9
|
+
py_modules=["starkerak"],
|
|
10
|
+
install_requires=[
|
|
11
|
+
"aiohttp>=3.8.0",
|
|
12
|
+
],
|
|
13
|
+
classifiers=[
|
|
14
|
+
"Programming Language :: Python :: 3.9",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
],
|
|
18
|
+
python_requires='>=3.8',
|
|
19
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: starkerak
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: StarKerak To'lov Monitoring API va Websocket Client
|
|
5
|
+
Author: StarKerak Jamoasi
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: classifier
|
|
13
|
+
Dynamic: requires-dist
|
|
14
|
+
Dynamic: requires-python
|
|
15
|
+
Dynamic: summary
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aiohttp>=3.8.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
starkerak
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
import logging
|
|
4
|
+
import aiohttp
|
|
5
|
+
|
|
6
|
+
class StarKerakClient:
|
|
7
|
+
def __init__(self, api_key: str, wss_url: str = "wss://writing-corporations-nation-flow.trycloudflare.com/api/ws/payments"):
|
|
8
|
+
"""
|
|
9
|
+
StarKerak Python Client
|
|
10
|
+
:param api_key: WebApp dagi 'Sozlamalar' bo'limidan olingan API Kalit
|
|
11
|
+
:param wss_url: Websocket server manzili (agar o'zgarsa)
|
|
12
|
+
"""
|
|
13
|
+
self.api_key = api_key
|
|
14
|
+
self.wss_url = wss_url
|
|
15
|
+
self._on_payment_handler = None
|
|
16
|
+
self._running = False
|
|
17
|
+
self.logger = logging.getLogger("StarKerakClient")
|
|
18
|
+
|
|
19
|
+
if not self.logger.handlers:
|
|
20
|
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(message)s")
|
|
21
|
+
|
|
22
|
+
def on_payment(self, func):
|
|
23
|
+
"""
|
|
24
|
+
Yangi to'lov tushganda ishga tushadigan funksiya (Decorator).
|
|
25
|
+
"""
|
|
26
|
+
self._on_payment_handler = func
|
|
27
|
+
return func
|
|
28
|
+
|
|
29
|
+
async def _listen_loop(self):
|
|
30
|
+
"""Websocket orqali serverga ulanish va kutish logikasi."""
|
|
31
|
+
url_with_auth = f"{self.wss_url}?api_key={self.api_key}"
|
|
32
|
+
|
|
33
|
+
while self._running:
|
|
34
|
+
try:
|
|
35
|
+
self.logger.info("StarKerak serveriga ulanilmoqda...")
|
|
36
|
+
async with aiohttp.ClientSession() as session:
|
|
37
|
+
async with session.ws_connect(url_with_auth, heartbeat=30.0) as ws:
|
|
38
|
+
self.logger.info("✅ Muvaffaqiyatli ulandi! To'lovlarni kutmoqda...")
|
|
39
|
+
|
|
40
|
+
async for msg in ws:
|
|
41
|
+
if msg.type == aiohttp.WSMsgType.TEXT:
|
|
42
|
+
data = json.loads(msg.data)
|
|
43
|
+
if self._on_payment_handler:
|
|
44
|
+
# Handler asinxron bo'lsa kutamiz, sinxron bo'lsa to'g'ridan to'g'ri chaqiramiz
|
|
45
|
+
if asyncio.iscoroutinefunction(self._on_payment_handler):
|
|
46
|
+
await self._on_payment_handler(data)
|
|
47
|
+
else:
|
|
48
|
+
self._on_payment_handler(data)
|
|
49
|
+
elif msg.type == aiohttp.WSMsgType.ERROR:
|
|
50
|
+
self.logger.error(f"WebSocket xatosi: {ws.exception()}")
|
|
51
|
+
break
|
|
52
|
+
except Exception as e:
|
|
53
|
+
self.logger.warning(f"Aloqa uzildi yoki ulanib bo'lmadi: {e}. 3 soniyadan so'ng qayta urinish...")
|
|
54
|
+
await asyncio.sleep(3)
|
|
55
|
+
|
|
56
|
+
def start_listening(self):
|
|
57
|
+
"""
|
|
58
|
+
Dasturni ishga tushirish (Sinxron kodlar uchun, asosan oddiy scriptlar uchun).
|
|
59
|
+
"""
|
|
60
|
+
self._running = True
|
|
61
|
+
try:
|
|
62
|
+
asyncio.run(self._listen_loop())
|
|
63
|
+
except KeyboardInterrupt:
|
|
64
|
+
self.logger.info("Dastur to'xtatildi.")
|
|
65
|
+
self._running = False
|
|
66
|
+
|
|
67
|
+
async def start_listening_async(self):
|
|
68
|
+
"""
|
|
69
|
+
Dasturni ishga tushirish (Asinxron kodlar / Aiogram botlar bilan birga ishlatish uchun).
|
|
70
|
+
"""
|
|
71
|
+
self._running = True
|
|
72
|
+
await self._listen_loop()
|