pay-engine 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.
- pay_engine-0.1.0/LICENSE +21 -0
- pay_engine-0.1.0/PKG-INFO +186 -0
- pay_engine-0.1.0/README.md +152 -0
- pay_engine-0.1.0/pyproject.toml +61 -0
- pay_engine-0.1.0/src/pay_engine/__init__.py +168 -0
- pay_engine-0.1.0/src/pay_engine/core/__init__.py +35 -0
- pay_engine-0.1.0/src/pay_engine/core/config.py +74 -0
- pay_engine-0.1.0/src/pay_engine/core/exceptions.py +30 -0
- pay_engine-0.1.0/src/pay_engine/core/models.py +51 -0
- pay_engine-0.1.0/src/pay_engine/integrations/__init__.py +14 -0
- pay_engine-0.1.0/src/pay_engine/integrations/fastapi.py +137 -0
- pay_engine-0.1.0/src/pay_engine/integrations/telegram.py +107 -0
- pay_engine-0.1.0/src/pay_engine/providers/__init__.py +16 -0
- pay_engine-0.1.0/src/pay_engine/providers/base.py +40 -0
- pay_engine-0.1.0/src/pay_engine/providers/click/__init__.py +6 -0
- pay_engine-0.1.0/src/pay_engine/providers/click/client.py +137 -0
- pay_engine-0.1.0/src/pay_engine/providers/click/handler.py +226 -0
- pay_engine-0.1.0/src/pay_engine/providers/payme/__init__.py +6 -0
- pay_engine-0.1.0/src/pay_engine/providers/payme/client.py +160 -0
- pay_engine-0.1.0/src/pay_engine/providers/payme/handler.py +255 -0
- pay_engine-0.1.0/src/pay_engine/providers/uzum/__init__.py +6 -0
- pay_engine-0.1.0/src/pay_engine/providers/uzum/client.py +61 -0
- pay_engine-0.1.0/src/pay_engine/providers/uzum/handler.py +82 -0
pay_engine-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Developer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pay-engine
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: All-in-one payment engine for Uzbekistan (Payme, Click, Uzum Bank) with one-liner links, Telegram buttons, and auto-charge.
|
|
5
|
+
Project-URL: Homepage, https://github.com/developer/pay-engine
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/developer/pay-engine/issues
|
|
7
|
+
Author-email: Developer <dev@example.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: aiogram,click,fastapi,fintech,payme,payment,telegram,uzbekistan,uzum
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Point-Of-Sale
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: httpx>=0.25.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: twine; extra == 'dev'
|
|
29
|
+
Provides-Extra: fastapi
|
|
30
|
+
Requires-Dist: fastapi>=0.100.0; extra == 'fastapi'
|
|
31
|
+
Provides-Extra: telegram
|
|
32
|
+
Requires-Dist: aiogram>=3.0.0; extra == 'telegram'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# 💳 pay-engine
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/pay-engine/)
|
|
38
|
+
[](https://pypi.org/project/pay-engine/)
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
|
|
41
|
+
**pay-engine** — O'zbekistonning barcha asosiy to'lov tizimlarini (**Payme**, **Click**, **Uzum Bank**) birlashtiruvchi, bir qator kod bilan to'lov havolalari yaratish, Telegram bot tugmalari hosil qilish va avtomatik pul yechish (auto-charge) imkonini beruvchi zamonaviy Python kutubxonasi.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 🚀 Imkoniyatlar (Features)
|
|
46
|
+
|
|
47
|
+
- ⚡ **1 qatorlik to'lov havolalari:** Payme, Click va Uzum Bank uchun bir lahzada to'lov linklarini olish.
|
|
48
|
+
- 🤖 **Telegram Botlar uchun tayyor klaviaturalar:** `aiogram` va boshqa botlar uchun tayyor `InlineKeyboardMarkup` tugmalari.
|
|
49
|
+
- 🛡️ **Avtomatlashtirilgan Webhooklar:** FastAPI va boshqa freymvorklarda imzolarni tekshirish va JSON-RPC protokoli bilan bosh qotirmasdan, faqat `on_success(order_id, amount)` orqali pul tushganini qabul qilish.
|
|
50
|
+
- 🔄 **Avtomatik yechish (Card Token / Auto-charge):** Karta tokeni orqali qayta SMS-kodsiz to'lov yechish (obunalar va Yandex Go kabi xizmatlar uchun).
|
|
51
|
+
- 🧩 **Zero-boilerplate:** `.env` faylidan kalitlarni avtomatik o'qib olish.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 📦 O'rnatish (Installation)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install pay-engine
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
FastAPI yoki Telegram bot integratsiyasi bilan birga o'rnatish uchun:
|
|
62
|
+
```bash
|
|
63
|
+
pip install "pay-engine[fastapi,telegram]"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## ⚙️ Sozlash (.env)
|
|
69
|
+
|
|
70
|
+
Loyihangizning `.env` fayliga kerakli to'lov tizimlari kalitlarini kiriting:
|
|
71
|
+
|
|
72
|
+
```env
|
|
73
|
+
# Payme
|
|
74
|
+
PAYME_MERCHANT_ID=your_payme_merchant_id
|
|
75
|
+
PAYME_SECRET_KEY=your_payme_secret_key
|
|
76
|
+
PAYME_TEST_MODE=false
|
|
77
|
+
|
|
78
|
+
# Click
|
|
79
|
+
CLICK_SERVICE_ID=your_click_service_id
|
|
80
|
+
CLICK_MERCHANT_ID=your_click_merchant_id
|
|
81
|
+
CLICK_SECRET_KEY=your_click_secret_key
|
|
82
|
+
CLICK_MERCHANT_USER_ID=your_click_user_id
|
|
83
|
+
|
|
84
|
+
# Uzum Bank
|
|
85
|
+
UZUM_SHOP_ID=your_uzum_shop_id
|
|
86
|
+
UZUM_SECRET_KEY=your_uzum_secret_key
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 📖 Foydalanish (Quickstart)
|
|
92
|
+
|
|
93
|
+
### 1. To'lov havolasini olish (1 qatorda)
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from pay_engine import payme, click, uzum
|
|
97
|
+
|
|
98
|
+
# Payme havolasi:
|
|
99
|
+
payme_url = payme.link(amount=100_000, order_id="ORDER_123")
|
|
100
|
+
|
|
101
|
+
# Click havolasi:
|
|
102
|
+
click_url = click.link(amount=100_000, order_id="ORDER_123")
|
|
103
|
+
|
|
104
|
+
# Uzum Bank havolasi:
|
|
105
|
+
uzum_url = uzum.link(amount=100_000, order_id="ORDER_123")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### 2. Telegram Botda to'lov tugmalarini chiqarish (aiogram)
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from aiogram import Bot, Dispatcher, types
|
|
114
|
+
from pay_engine.integrations.telegram import payment_buttons
|
|
115
|
+
|
|
116
|
+
bot = Bot(token="BOT_TOKEN")
|
|
117
|
+
dp = Dispatcher()
|
|
118
|
+
|
|
119
|
+
@dp.message(lambda msg: msg.text == "/tolov")
|
|
120
|
+
async def pay_command(message: types.Message):
|
|
121
|
+
# Bir qatorda Payme, Click va Uzum tugmalarini yasaymiz:
|
|
122
|
+
keyboard = payment_buttons(
|
|
123
|
+
amount=75_000,
|
|
124
|
+
order_id=message.from_user.id
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
await message.answer(
|
|
128
|
+
"To'lov qilish uchun qulay tizimni tanlang:",
|
|
129
|
+
reply_markup=keyboard
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### 3. FastAPI da pul tushganini ushlash (Webhook)
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from fastapi import FastAPI
|
|
139
|
+
from pay_engine.integrations.fastapi import pay_router
|
|
140
|
+
|
|
141
|
+
app = FastAPI()
|
|
142
|
+
|
|
143
|
+
# Pul muvaffaqiyatli tushganda bajariladigan funksiya:
|
|
144
|
+
async def tolov_tasdiqlandi(order_id: str, amount: float):
|
|
145
|
+
print(f"✅ Pul to'landi: Buyurtma #{order_id}, Summa: {amount:,.0f} so'm")
|
|
146
|
+
# Bazangizda buyurtma statusini o'zgartiring
|
|
147
|
+
|
|
148
|
+
# Bitta qatorda /payments/payme, /payments/click, /payments/uzum ulanadi:
|
|
149
|
+
app.include_router(pay_router(on_success=tolov_tasdiqlandi))
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### 4. Avtomatik yechish (Card Token Auto-charge)
|
|
155
|
+
|
|
156
|
+
Mijozning saqlangan karta tokeni orqali hisobidan avtomatik pul yechib olish:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from pay_engine import payme
|
|
160
|
+
|
|
161
|
+
result = payme.charge(
|
|
162
|
+
card_token="saved_card_token_abc123",
|
|
163
|
+
amount=50_000,
|
|
164
|
+
order_id="SUB_999",
|
|
165
|
+
description="Oylik obuna to'lovi"
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
if result.success:
|
|
169
|
+
print(f"Pul yechildi! Tranzaksiya ID: {result.transaction_id}")
|
|
170
|
+
else:
|
|
171
|
+
print(f"Xatolik yuz berdi: {result.message}")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 🧪 Testlarni ishga tushirish
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
python -m unittest discover -s tests -p "test_*.py"
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 📄 Litsenziya
|
|
185
|
+
|
|
186
|
+
MIT License. Ochiq va bepul foydalanish mumkin!
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# 💳 pay-engine
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pay-engine/)
|
|
4
|
+
[](https://pypi.org/project/pay-engine/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**pay-engine** — O'zbekistonning barcha asosiy to'lov tizimlarini (**Payme**, **Click**, **Uzum Bank**) birlashtiruvchi, bir qator kod bilan to'lov havolalari yaratish, Telegram bot tugmalari hosil qilish va avtomatik pul yechish (auto-charge) imkonini beruvchi zamonaviy Python kutubxonasi.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🚀 Imkoniyatlar (Features)
|
|
12
|
+
|
|
13
|
+
- ⚡ **1 qatorlik to'lov havolalari:** Payme, Click va Uzum Bank uchun bir lahzada to'lov linklarini olish.
|
|
14
|
+
- 🤖 **Telegram Botlar uchun tayyor klaviaturalar:** `aiogram` va boshqa botlar uchun tayyor `InlineKeyboardMarkup` tugmalari.
|
|
15
|
+
- 🛡️ **Avtomatlashtirilgan Webhooklar:** FastAPI va boshqa freymvorklarda imzolarni tekshirish va JSON-RPC protokoli bilan bosh qotirmasdan, faqat `on_success(order_id, amount)` orqali pul tushganini qabul qilish.
|
|
16
|
+
- 🔄 **Avtomatik yechish (Card Token / Auto-charge):** Karta tokeni orqali qayta SMS-kodsiz to'lov yechish (obunalar va Yandex Go kabi xizmatlar uchun).
|
|
17
|
+
- 🧩 **Zero-boilerplate:** `.env` faylidan kalitlarni avtomatik o'qib olish.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📦 O'rnatish (Installation)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install pay-engine
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
FastAPI yoki Telegram bot integratsiyasi bilan birga o'rnatish uchun:
|
|
28
|
+
```bash
|
|
29
|
+
pip install "pay-engine[fastapi,telegram]"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ⚙️ Sozlash (.env)
|
|
35
|
+
|
|
36
|
+
Loyihangizning `.env` fayliga kerakli to'lov tizimlari kalitlarini kiriting:
|
|
37
|
+
|
|
38
|
+
```env
|
|
39
|
+
# Payme
|
|
40
|
+
PAYME_MERCHANT_ID=your_payme_merchant_id
|
|
41
|
+
PAYME_SECRET_KEY=your_payme_secret_key
|
|
42
|
+
PAYME_TEST_MODE=false
|
|
43
|
+
|
|
44
|
+
# Click
|
|
45
|
+
CLICK_SERVICE_ID=your_click_service_id
|
|
46
|
+
CLICK_MERCHANT_ID=your_click_merchant_id
|
|
47
|
+
CLICK_SECRET_KEY=your_click_secret_key
|
|
48
|
+
CLICK_MERCHANT_USER_ID=your_click_user_id
|
|
49
|
+
|
|
50
|
+
# Uzum Bank
|
|
51
|
+
UZUM_SHOP_ID=your_uzum_shop_id
|
|
52
|
+
UZUM_SECRET_KEY=your_uzum_secret_key
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 📖 Foydalanish (Quickstart)
|
|
58
|
+
|
|
59
|
+
### 1. To'lov havolasini olish (1 qatorda)
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from pay_engine import payme, click, uzum
|
|
63
|
+
|
|
64
|
+
# Payme havolasi:
|
|
65
|
+
payme_url = payme.link(amount=100_000, order_id="ORDER_123")
|
|
66
|
+
|
|
67
|
+
# Click havolasi:
|
|
68
|
+
click_url = click.link(amount=100_000, order_id="ORDER_123")
|
|
69
|
+
|
|
70
|
+
# Uzum Bank havolasi:
|
|
71
|
+
uzum_url = uzum.link(amount=100_000, order_id="ORDER_123")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### 2. Telegram Botda to'lov tugmalarini chiqarish (aiogram)
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from aiogram import Bot, Dispatcher, types
|
|
80
|
+
from pay_engine.integrations.telegram import payment_buttons
|
|
81
|
+
|
|
82
|
+
bot = Bot(token="BOT_TOKEN")
|
|
83
|
+
dp = Dispatcher()
|
|
84
|
+
|
|
85
|
+
@dp.message(lambda msg: msg.text == "/tolov")
|
|
86
|
+
async def pay_command(message: types.Message):
|
|
87
|
+
# Bir qatorda Payme, Click va Uzum tugmalarini yasaymiz:
|
|
88
|
+
keyboard = payment_buttons(
|
|
89
|
+
amount=75_000,
|
|
90
|
+
order_id=message.from_user.id
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
await message.answer(
|
|
94
|
+
"To'lov qilish uchun qulay tizimni tanlang:",
|
|
95
|
+
reply_markup=keyboard
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### 3. FastAPI da pul tushganini ushlash (Webhook)
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from fastapi import FastAPI
|
|
105
|
+
from pay_engine.integrations.fastapi import pay_router
|
|
106
|
+
|
|
107
|
+
app = FastAPI()
|
|
108
|
+
|
|
109
|
+
# Pul muvaffaqiyatli tushganda bajariladigan funksiya:
|
|
110
|
+
async def tolov_tasdiqlandi(order_id: str, amount: float):
|
|
111
|
+
print(f"✅ Pul to'landi: Buyurtma #{order_id}, Summa: {amount:,.0f} so'm")
|
|
112
|
+
# Bazangizda buyurtma statusini o'zgartiring
|
|
113
|
+
|
|
114
|
+
# Bitta qatorda /payments/payme, /payments/click, /payments/uzum ulanadi:
|
|
115
|
+
app.include_router(pay_router(on_success=tolov_tasdiqlandi))
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### 4. Avtomatik yechish (Card Token Auto-charge)
|
|
121
|
+
|
|
122
|
+
Mijozning saqlangan karta tokeni orqali hisobidan avtomatik pul yechib olish:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from pay_engine import payme
|
|
126
|
+
|
|
127
|
+
result = payme.charge(
|
|
128
|
+
card_token="saved_card_token_abc123",
|
|
129
|
+
amount=50_000,
|
|
130
|
+
order_id="SUB_999",
|
|
131
|
+
description="Oylik obuna to'lovi"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
if result.success:
|
|
135
|
+
print(f"Pul yechildi! Tranzaksiya ID: {result.transaction_id}")
|
|
136
|
+
else:
|
|
137
|
+
print(f"Xatolik yuz berdi: {result.message}")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🧪 Testlarni ishga tushirish
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
python -m unittest discover -s tests -p "test_*.py"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 📄 Litsenziya
|
|
151
|
+
|
|
152
|
+
MIT License. Ochiq va bepul foydalanish mumkin!
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pay-engine"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Developer", email = "dev@example.com" }
|
|
10
|
+
]
|
|
11
|
+
description = "All-in-one payment engine for Uzbekistan (Payme, Click, Uzum Bank) with one-liner links, Telegram buttons, and auto-charge."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
license = { text = "MIT" }
|
|
15
|
+
keywords = ["payme", "click", "uzum", "payment", "uzbekistan", "fintech", "fastapi", "telegram", "aiogram"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
"Topic :: Office/Business :: Financial :: Point-Of-Sale",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"httpx>=0.25.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
fastapi = [
|
|
35
|
+
"fastapi>=0.100.0",
|
|
36
|
+
]
|
|
37
|
+
telegram = [
|
|
38
|
+
"aiogram>=3.0.0",
|
|
39
|
+
]
|
|
40
|
+
dev = [
|
|
41
|
+
"pytest>=7.0.0",
|
|
42
|
+
"pytest-asyncio>=0.21.0",
|
|
43
|
+
"build",
|
|
44
|
+
"twine",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
"Homepage" = "https://github.com/developer/pay-engine"
|
|
49
|
+
"Bug Tracker" = "https://github.com/developer/pay-engine/issues"
|
|
50
|
+
|
|
51
|
+
[tool.hatch.build.targets.wheel]
|
|
52
|
+
packages = ["src/pay_engine"]
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.sdist]
|
|
55
|
+
include = [
|
|
56
|
+
"/src",
|
|
57
|
+
"/README.md",
|
|
58
|
+
"/LICENSE",
|
|
59
|
+
"/pyproject.toml",
|
|
60
|
+
]
|
|
61
|
+
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pay-engine: All-in-one payment engine for Uzbekistan.
|
|
3
|
+
Supports Payme, Click, and Uzum Bank with one-liners, Telegram buttons, and auto-charge.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Any, Dict, List, Optional, Union
|
|
7
|
+
|
|
8
|
+
from .core.config import ClickConfig, PaymeConfig, UzumConfig
|
|
9
|
+
from .core.exceptions import (
|
|
10
|
+
CardTokenError,
|
|
11
|
+
ConfigurationError,
|
|
12
|
+
InvalidAmountError,
|
|
13
|
+
OrderNotFoundError,
|
|
14
|
+
PayEngineError,
|
|
15
|
+
SignatureVerificationError,
|
|
16
|
+
)
|
|
17
|
+
from .core.models import (
|
|
18
|
+
CardChargeRequest,
|
|
19
|
+
CardChargeResult,
|
|
20
|
+
PaymentRequest,
|
|
21
|
+
TransactionStatus,
|
|
22
|
+
WebhookResult,
|
|
23
|
+
)
|
|
24
|
+
from .providers.click.client import ClickClient
|
|
25
|
+
from .providers.click.handler import ClickHandler
|
|
26
|
+
from .providers.payme.client import PaymeClient
|
|
27
|
+
from .providers.payme.handler import PaymeHandler
|
|
28
|
+
from .providers.uzum.client import UzumClient
|
|
29
|
+
from .providers.uzum.handler import UzumHandler
|
|
30
|
+
|
|
31
|
+
__version__ = "0.1.0"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class _PaymeProxy:
|
|
35
|
+
"""Convenience helper for Payme one-liners."""
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def link(
|
|
39
|
+
amount: float,
|
|
40
|
+
order_id: Union[str, int],
|
|
41
|
+
return_url: Optional[str] = None,
|
|
42
|
+
merchant_id: Optional[str] = None,
|
|
43
|
+
test_mode: Optional[bool] = None,
|
|
44
|
+
**kwargs: Any,
|
|
45
|
+
) -> str:
|
|
46
|
+
client = PaymeClient(merchant_id=merchant_id, test_mode=test_mode)
|
|
47
|
+
return client.create_link(amount=amount, order_id=order_id, return_url=return_url, **kwargs)
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def charge(
|
|
51
|
+
card_token: str,
|
|
52
|
+
amount: float,
|
|
53
|
+
order_id: Union[str, int],
|
|
54
|
+
secret_key: Optional[str] = None,
|
|
55
|
+
description: Optional[str] = None,
|
|
56
|
+
**kwargs: Any,
|
|
57
|
+
) -> CardChargeResult:
|
|
58
|
+
client = PaymeClient(secret_key=secret_key)
|
|
59
|
+
return client.charge_card(card_token=card_token, amount=amount, order_id=order_id, description=description, **kwargs)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class _ClickProxy:
|
|
63
|
+
"""Convenience helper for Click one-liners."""
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
def link(
|
|
67
|
+
amount: float,
|
|
68
|
+
order_id: Union[str, int],
|
|
69
|
+
return_url: Optional[str] = None,
|
|
70
|
+
service_id: Optional[str] = None,
|
|
71
|
+
merchant_id: Optional[str] = None,
|
|
72
|
+
**kwargs: Any,
|
|
73
|
+
) -> str:
|
|
74
|
+
client = ClickClient(service_id=service_id, merchant_id=merchant_id)
|
|
75
|
+
return client.create_link(amount=amount, order_id=order_id, return_url=return_url, **kwargs)
|
|
76
|
+
|
|
77
|
+
@staticmethod
|
|
78
|
+
def charge(
|
|
79
|
+
card_token: str,
|
|
80
|
+
amount: float,
|
|
81
|
+
order_id: Union[str, int],
|
|
82
|
+
service_id: Optional[str] = None,
|
|
83
|
+
secret_key: Optional[str] = None,
|
|
84
|
+
merchant_user_id: Optional[str] = None,
|
|
85
|
+
**kwargs: Any,
|
|
86
|
+
) -> CardChargeResult:
|
|
87
|
+
client = ClickClient(service_id=service_id, secret_key=secret_key, merchant_user_id=merchant_user_id)
|
|
88
|
+
return client.charge_card(card_token=card_token, amount=amount, order_id=order_id, **kwargs)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class _UzumProxy:
|
|
92
|
+
"""Convenience helper for Uzum Bank one-liners."""
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def link(
|
|
96
|
+
amount: float,
|
|
97
|
+
order_id: Union[str, int],
|
|
98
|
+
return_url: Optional[str] = None,
|
|
99
|
+
shop_id: Optional[str] = None,
|
|
100
|
+
**kwargs: Any,
|
|
101
|
+
) -> str:
|
|
102
|
+
client = UzumClient(shop_id=shop_id)
|
|
103
|
+
return client.create_link(amount=amount, order_id=order_id, return_url=return_url, **kwargs)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class PayEngine:
|
|
107
|
+
"""Unified master engine for payments."""
|
|
108
|
+
|
|
109
|
+
def __init__(
|
|
110
|
+
self,
|
|
111
|
+
payme_merchant_id: Optional[str] = None,
|
|
112
|
+
payme_secret_key: Optional[str] = None,
|
|
113
|
+
click_service_id: Optional[str] = None,
|
|
114
|
+
click_merchant_id: Optional[str] = None,
|
|
115
|
+
click_secret_key: Optional[str] = None,
|
|
116
|
+
uzum_shop_id: Optional[str] = None,
|
|
117
|
+
uzum_secret_key: Optional[str] = None,
|
|
118
|
+
test_mode: bool = False,
|
|
119
|
+
):
|
|
120
|
+
self.payme = PaymeClient(merchant_id=payme_merchant_id, secret_key=payme_secret_key, test_mode=test_mode) if (payme_merchant_id or PaymeConfig().merchant_id) else None
|
|
121
|
+
self.click = ClickClient(service_id=click_service_id, merchant_id=click_merchant_id, secret_key=click_secret_key) if (click_service_id or ClickConfig().service_id) else None
|
|
122
|
+
self.uzum = UzumClient(shop_id=uzum_shop_id, secret_key=uzum_secret_key) if (uzum_shop_id or UzumConfig().shop_id) else None
|
|
123
|
+
|
|
124
|
+
def get_links(
|
|
125
|
+
self,
|
|
126
|
+
amount: float,
|
|
127
|
+
order_id: Union[str, int],
|
|
128
|
+
return_url: Optional[str] = None,
|
|
129
|
+
) -> Dict[str, str]:
|
|
130
|
+
"""Returns checkout URLs for all configured providers."""
|
|
131
|
+
links = {}
|
|
132
|
+
if self.payme:
|
|
133
|
+
links["payme"] = self.payme.create_link(amount=amount, order_id=order_id, return_url=return_url)
|
|
134
|
+
if self.click:
|
|
135
|
+
links["click"] = self.click.create_link(amount=amount, order_id=order_id, return_url=return_url)
|
|
136
|
+
if self.uzum:
|
|
137
|
+
links["uzum"] = self.uzum.create_link(amount=amount, order_id=order_id, return_url=return_url)
|
|
138
|
+
return links
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
# Public helper instances
|
|
142
|
+
payme = _PaymeProxy()
|
|
143
|
+
click = _ClickProxy()
|
|
144
|
+
uzum = _UzumProxy()
|
|
145
|
+
|
|
146
|
+
__all__ = [
|
|
147
|
+
"PayEngine",
|
|
148
|
+
"payme",
|
|
149
|
+
"click",
|
|
150
|
+
"uzum",
|
|
151
|
+
"PaymeClient",
|
|
152
|
+
"PaymeHandler",
|
|
153
|
+
"ClickClient",
|
|
154
|
+
"ClickHandler",
|
|
155
|
+
"UzumClient",
|
|
156
|
+
"UzumHandler",
|
|
157
|
+
"PayEngineError",
|
|
158
|
+
"ConfigurationError",
|
|
159
|
+
"SignatureVerificationError",
|
|
160
|
+
"InvalidAmountError",
|
|
161
|
+
"OrderNotFoundError",
|
|
162
|
+
"CardTokenError",
|
|
163
|
+
"TransactionStatus",
|
|
164
|
+
"PaymentRequest",
|
|
165
|
+
"WebhookResult",
|
|
166
|
+
"CardChargeRequest",
|
|
167
|
+
"CardChargeResult",
|
|
168
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Core module for pay-engine."""
|
|
2
|
+
|
|
3
|
+
from .config import ClickConfig, PaymeConfig, UzumConfig
|
|
4
|
+
from .exceptions import (
|
|
5
|
+
CardTokenError,
|
|
6
|
+
ConfigurationError,
|
|
7
|
+
InvalidAmountError,
|
|
8
|
+
OrderNotFoundError,
|
|
9
|
+
PayEngineError,
|
|
10
|
+
SignatureVerificationError,
|
|
11
|
+
)
|
|
12
|
+
from .models import (
|
|
13
|
+
CardChargeRequest,
|
|
14
|
+
CardChargeResult,
|
|
15
|
+
PaymentRequest,
|
|
16
|
+
TransactionStatus,
|
|
17
|
+
WebhookResult,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"PayEngineError",
|
|
22
|
+
"ConfigurationError",
|
|
23
|
+
"SignatureVerificationError",
|
|
24
|
+
"InvalidAmountError",
|
|
25
|
+
"OrderNotFoundError",
|
|
26
|
+
"CardTokenError",
|
|
27
|
+
"TransactionStatus",
|
|
28
|
+
"PaymentRequest",
|
|
29
|
+
"WebhookResult",
|
|
30
|
+
"CardChargeRequest",
|
|
31
|
+
"CardChargeResult",
|
|
32
|
+
"PaymeConfig",
|
|
33
|
+
"ClickConfig",
|
|
34
|
+
"UzumConfig",
|
|
35
|
+
]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Configuration management for pay-engine."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _load_env_file():
|
|
9
|
+
"""Simple parser to load .env file if it exists, without needing python-dotenv."""
|
|
10
|
+
env_path = os.path.join(os.getcwd(), ".env")
|
|
11
|
+
if os.path.isfile(env_path):
|
|
12
|
+
try:
|
|
13
|
+
with open(env_path, "r", encoding="utf-8") as f:
|
|
14
|
+
for line in f:
|
|
15
|
+
line = line.strip()
|
|
16
|
+
if not line or line.startswith("#") or "=" not in line:
|
|
17
|
+
continue
|
|
18
|
+
key, val = line.split("=", 1)
|
|
19
|
+
key = key.strip()
|
|
20
|
+
val = val.strip().strip("'\"")
|
|
21
|
+
if key not in os.environ:
|
|
22
|
+
os.environ[key] = val
|
|
23
|
+
except Exception:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Automatically attempt to load .env on module import
|
|
28
|
+
_load_env_file()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class PaymeConfig:
|
|
33
|
+
merchant_id: Optional[str] = None
|
|
34
|
+
secret_key: Optional[str] = None
|
|
35
|
+
test_mode: bool = False
|
|
36
|
+
|
|
37
|
+
def __post_init__(self):
|
|
38
|
+
if not self.merchant_id:
|
|
39
|
+
self.merchant_id = os.getenv("PAYME_MERCHANT_ID")
|
|
40
|
+
if not self.secret_key:
|
|
41
|
+
self.secret_key = os.getenv("PAYME_SECRET_KEY")
|
|
42
|
+
test_env = os.getenv("PAYME_TEST_MODE", "").lower()
|
|
43
|
+
if test_env in ("1", "true", "yes"):
|
|
44
|
+
self.test_mode = True
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class ClickConfig:
|
|
49
|
+
service_id: Optional[str] = None
|
|
50
|
+
merchant_id: Optional[str] = None
|
|
51
|
+
secret_key: Optional[str] = None
|
|
52
|
+
merchant_user_id: Optional[str] = None
|
|
53
|
+
|
|
54
|
+
def __post_init__(self):
|
|
55
|
+
if not self.service_id:
|
|
56
|
+
self.service_id = os.getenv("CLICK_SERVICE_ID")
|
|
57
|
+
if not self.merchant_id:
|
|
58
|
+
self.merchant_id = os.getenv("CLICK_MERCHANT_ID")
|
|
59
|
+
if not self.secret_key:
|
|
60
|
+
self.secret_key = os.getenv("CLICK_SECRET_KEY")
|
|
61
|
+
if not self.merchant_user_id:
|
|
62
|
+
self.merchant_user_id = os.getenv("CLICK_MERCHANT_USER_ID")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass
|
|
66
|
+
class UzumConfig:
|
|
67
|
+
shop_id: Optional[str] = None
|
|
68
|
+
secret_key: Optional[str] = None
|
|
69
|
+
|
|
70
|
+
def __post_init__(self):
|
|
71
|
+
if not self.shop_id:
|
|
72
|
+
self.shop_id = os.getenv("UZUM_SHOP_ID")
|
|
73
|
+
if not self.secret_key:
|
|
74
|
+
self.secret_key = os.getenv("UZUM_SECRET_KEY")
|