PayTechUZ — Payme, Click, Uzum, Paynet and Octo payments for Python
One library for the payment gateways used in Uzbekistan — Payme, Click, Uzum, Paynet and Octo — with the same interface for each, and webhook handlers for Django and FastAPI that you subclass instead of writing.
Fully open source: pure Python, no compiled extensions. Everything the package does at runtime is in this repository.
📖 Documentation | 💬 Telegram | 📋 Changelog
pip install paytechuz
🇺🇿 Payme, Click, Uzum, Paynet va Octo integratsiyasi — Django va FastAPI uchun bitta Python kutubxonasi.
🇷🇺 Интеграция Payme, Click, Uzum, Paynet и Octo — одна Python-библиотека для Django и FastAPI.
Contents
- Features
- Compatibility
- Installation
- Quick Start
- Django Integration
- FastAPI Integration
- The transaction table
- Project layout
- Development
- Contributing
- License
Features
- Unified API: consistent interface for multiple payment providers
- Framework integration: native support for Django and FastAPI
- Webhook handling: ready-to-use webhook handlers for payment notifications
- Transaction management: automatic transaction tracking in a single table
- Extensible: adding a new provider means adding one gateway and one webhook class
Compatibility
| Supported | |
|---|---|
| Python | 3.8 – 3.12 |
| Django | 3.2 – 6.0 (tested on 4.2, 5.2, 6.0) |
| FastAPI | 0.68 – 0.x, with SQLAlchemy 1.4 – 2.x and pydantic 2.x |
| Gateways | Payme, Click, Uzum, Paynet, Octo |
Webhook handlers for Uzum, Paynet and Octo are currently Django only. Payme and Click are available on both frameworks.
Installation
pip install paytechuz
# For Django
pip install "paytechuz[django]"
# For FastAPI
pip install "paytechuz[fastapi]"
Quick Start
Generate payment links
from paytechuz.gateways.payme import PaymeGateway
from paytechuz.gateways.click import ClickGateway
from paytechuz.gateways.uzum import UzumGateway
from paytechuz.gateways.paynet import PaynetGateway
from paytechuz.gateways.octo import OctoGateway
# Payme
payme = PaymeGateway(
payme_id="your_payme_id",
payme_key="your_payme_key",
is_test_mode=True, # Set to False in production
)
# Click
click = ClickGateway(
service_id="your_service_id",
merchant_id="your_merchant_id",
merchant_user_id="your_merchant_user_id",
secret_key="your_secret_key",
is_test_mode=True,
)
# Uzum (Biller / open-service)
uzum = UzumGateway(
service_id="your_service_id",
is_test_mode=True,
)
# Paynet
paynet = PaynetGateway(
merchant_id="your_merchant_id", # accepts both str and int
is_test_mode=False,
)
# Octo
octo = OctoGateway(
octo_shop_id=123,
octo_secret="your_octo_secret",
notify_url="https://example.com/payments/webhook/octo/",
is_test_mode=True,
)
# Payme — amount in som. account_field_name is the field name used in the
# payment URL (e.g. ac.id=123). Default: "order_id".
payme_link = payme.create_payment(
id="order_123",
amount=150000,
return_url="https://example.com/return",
account_field_name="id",
)
# Click — amount in som
click_link = click.create_payment(
id="order_123",
amount=150000,
description="Test payment",
return_url="https://example.com/return",
)
# Uzum — amount in som, converted to tiyin in the URL
uzum_link = uzum.create_payment(
id="order_123",
amount=100000,
return_url="https://example.com/callback",
)
# https://www.uzumbank.uz/open-service?serviceId=...&order_id=order_123&amount=10000000&redirectUrl=...
# Paynet — amount in tiyin, optional
paynet_link = paynet.create_payment(id="order_123", amount=15000000)
# https://app.paynet.uz/?m=your_merchant_id&c=order_123&a=15000000
paynet_link_no_amount = paynet.create_payment(id="order_123")
# https://app.paynet.uz/?m=your_merchant_id&c=order_123
# Octo — amount in som, one-stage (auto_capture)
octo_link = octo.create_payment(
id="order_123",
amount=50000,
return_url="https://example.com/payment/done/",
description="Order #123",
)
You can also build a gateway by name:
from paytechuz import create_gateway
payme = create_gateway("payme", payme_id="...", payme_key="...", is_test_mode=True)
Provider notes
Payme account_field_name — only Payme uses this parameter. It sets the account
key inside the payment URL (ac.<account_field_name>=<id>). Other gateways ignore it.
Paynet — URL-based, mobile-first:
- URL format:
https://app.paynet.uz/?m={merchant_id}&c={payment_id}&a={amount} merchant_idaccepts bothstrandintamountis optional and expressed in tiyin- no return URL support
- desktop users scan a QR code, mobile users open the Paynet app
- payment status arrives through JSON-RPC 2.0 webhooks
Django Integration
- Create your order model:
# models.py
from django.db import models
from django.utils import timezone
class Order(models.Model):
STATUS_CHOICES = (
('pending', 'Pending'),
('paid', 'Paid'),
('cancelled', 'Cancelled'),
('delivered', 'Delivered'),
)
product_name = models.CharField(max_length=255)
amount = models.DecimalField(max_digits=12, decimal_places=2)
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
created_at = models.DateTimeField(default=timezone.now)
def __str__(self):
return f"{self.id} - {self.product_name} ({self.amount})"
- Add the app and configure the settings:
# settings.py
INSTALLED_APPS = [
# ...
'paytechuz.integrations.django',
]
PAYTECHUZ = {
'PAYME': {
'PAYME_ID': 'your_payme_id',
'PAYME_KEY': 'your_payme_key',
'ACCOUNT_MODEL': 'orders.models.Order',
'ACCOUNT_FIELD': 'id', # = account_field_name of the payment link
'AMOUNT_FIELD': 'amount',
'ONE_TIME_PAYMENT': True,
},
'CLICK': {
'SERVICE_ID': 'your_service_id',
'MERCHANT_ID': 'your_merchant_id',
'MERCHANT_USER_ID': 'your_merchant_user_id',
'SECRET_KEY': 'your_secret_key',
'ACCOUNT_MODEL': 'orders.models.Order',
'ACCOUNT_FIELD': 'id',
'AMOUNT_FIELD': 'amount',
'COMMISSION_PERCENT': 0.0,
'ONE_TIME_PAYMENT': True,
},
'UZUM': {
'SERVICE_ID': 'your_service_id',
'USERNAME': 'your_uzum_username', # webhook Basic auth
'PASSWORD': 'your_uzum_password', # webhook Basic auth
'ALLOWED_IPS': ['...'], # Uzum's addresses; omit to accept any
# 'IP_HEADER': 'HTTP_X_REAL_IP', # behind nginx
'ACCOUNT_MODEL': 'orders.models.Order',
'ACCOUNT_FIELD': 'order_id', # or 'id'
'AMOUNT_FIELD': 'amount',
'ONE_TIME_PAYMENT': True,
},
'PAYNET': {
'SERVICE_ID': 'your_paynet_service_id',
'USERNAME': 'your_paynet_username',
'PASSWORD': 'your_paynet_password',
'ACCOUNT_MODEL': 'orders.models.Order',
'ACCOUNT_FIELD': 'id', # the key Paynet sends in params.fields
'AMOUNT_FIELD': 'amount',
'ONE_TIME_PAYMENT': True,
},
'OCTO_BANK': {
'OCTO_SHOP_ID': 42125,
'OCTO_SECRET': 'your_octo_secret',
'OCTO_UNIQUE_KEY': 'your_octo_unique_key', # required in production
'NOTIFY_URL': 'https://example.com/payments/webhook/octo/',
'ACCOUNT_MODEL': 'orders.models.Order',
'ACCOUNT_FIELD': 'id',
'AMOUNT_FIELD': 'amount',
'ONE_TIME_PAYMENT': True,
'TEST_MODE': True, # False in production — enables signature verification
},
}
Note:
is_test_modeis a gateway constructor argument, not a webhook setting. Webhooks receive requests on the same URL in both test and production.
AMOUNT_FIELD holds som. Payme, Paynet and Uzum send tiyin; the webhooks
convert before comparing. ACCOUNT_FIELD: 'order_id' looks the account up by
its id.
- Run migrations:
python manage.py migrate
- Create the webhook views:
# views.py
from paytechuz.integrations.django.views import (
BasePaymeWebhookView,
BaseClickWebhookView,
BaseUzumWebhookView,
BasePaynetWebhookView,
BaseOctoWebhookView,
)
from .models import Order
class PaymeWebhookView(BasePaymeWebhookView):
def successfully_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'paid'
order.save()
def cancelled_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'cancelled'
order.save()
def get_check_data(self, params, account): # optional
# Extra data for CheckPerformTransaction (fiscal receipt)
return {
"detail": {
"receipt_type": 0,
"shipping": {"title": "Yetkazib berish", "price": 10000},
"items": [
{
"discount": 0,
"title": account.product_name,
"price": int(account.amount * 100),
"count": 1,
"code": "00001",
"units": 1,
"vat_percent": 0,
"package_code": "123456",
}
],
},
}
class ClickWebhookView(BaseClickWebhookView):
def successfully_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'paid'
order.save()
def cancelled_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'cancelled'
order.save()
class UzumWebhookView(BaseUzumWebhookView):
def successfully_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'paid'
order.save()
def cancelled_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'cancelled'
order.save()
def get_check_data(self, params, account): # optional
# Shown to the payer in the Uzum app before paying
return {"fio": {"value": account.product_name}}
class PaynetWebhookView(BasePaynetWebhookView):
def successfully_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'paid'
order.save()
def cancelled_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'cancelled'
order.save()
def get_check_data(self, params, account): # optional
# Extra data for GetInformation, shown to the payer
return {"fields": {"amount": int(account.amount)}}
class OctoWebhookView(BaseOctoWebhookView):
def successfully_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'paid'
order.save()
def cancelled_payment(self, params, transaction):
order = Order.objects.get(id=transaction.account_id)
order.status = 'cancelled'
order.save()
- Register the webhook URLs:
# urls.py
from django.urls import path
from .views import (
PaymeWebhookView,
ClickWebhookView,
UzumWebhookView,
PaynetWebhookView,
OctoWebhookView,
)
urlpatterns = [
path('payments/webhook/payme/', PaymeWebhookView.as_view(), name='payme_webhook'),
path('payments/webhook/click/', ClickWebhookView.as_view(), name='click_webhook'),
path('payments/webhook/uzum/<str:action>/', UzumWebhookView.as_view(), name='uzum_webhook'),
path('payments/webhook/paynet/', PaynetWebhookView.as_view(), name='paynet_webhook'),
path('payments/webhook/octo/', OctoWebhookView.as_view(), name='octo_webhook'),
]
- Send the customer to pay. The id in the link is the account the webhook looks up:
# views.py
from django.conf import settings
from django.shortcuts import get_object_or_404, redirect
from paytechuz.gateways.payme import PaymeGateway
from .models import Order
def pay_with_payme(request, order_id):
order = get_object_or_404(Order, id=order_id, status='pending')
payme = PaymeGateway(
payme_id=settings.PAYTECHUZ['PAYME']['PAYME_ID'],
payme_key=settings.PAYTECHUZ['PAYME']['PAYME_KEY'],
is_test_mode=False,
)
return redirect(payme.create_payment(
id=order.id,
amount=order.amount,
return_url='https://example.com/orders/',
account_field_name=settings.PAYTECHUZ['PAYME']['ACCOUNT_FIELD'],
))
Click and Uzum take amount in som the same way. Paynet's link takes tiyin:
PaynetGateway(merchant_id=...).create_payment(id=order.id, amount=int(order.amount * 100)).
Several kassas on one URL
One business often holds several merchant accounts with one provider: a live
kassa and a sandbox one, or one per brand. Since 0.5.0 each Django webhook
serves them all from one URL. List them under KASSAS; the provider's own
credentials decide which kassa a call belongs to:
| Gateway | A call is matched by |
|---|---|
| Payme | the key in its Basic auth header (PAYME_KEY) |
| Click | service_id in the body (SERVICE_ID, signed with that kassa's SECRET_KEY) |
| Paynet | serviceId in the body, else the login (USERNAME) |
| Uzum | the Basic auth login (USERNAME); the call must then name that kassa's serviceId |
PAYTECHUZ = {
'PAYME': {
'KASSAS': {
'shop': {'PAYME_ID': '...', 'PAYME_KEY': '...'},
'gifts': {'PAYME_ID': '...', 'PAYME_KEY': '...'},
},
'KASSA_FIELD': 'kassa', # optional, see below
'ACCOUNT_MODEL': 'orders.models.Order',
'ACCOUNT_FIELD': 'id',
'AMOUNT_FIELD': 'amount',
'ONE_TIME_PAYMENT': True,
},
'CLICK': {
'KASSAS': {
'shop': {'SERVICE_ID': '...', 'SECRET_KEY': '...'},
},
# ACCOUNT_MODEL etc. as above
},
'PAYNET': {
'KASSAS': {
'live': {'SERVICE_ID': '1001', 'USERNAME': '...', 'PASSWORD': '...'},
'test': {'SERVICE_ID': '1003', 'USERNAME': '...', 'PASSWORD': '...',
'IS_SANDBOX': True},
},
# 'CREDENTIAL_MODEL': 'paytechuz.integrations.django.models.PaynetCredential',
},
'UZUM': {
'KASSAS': {
'shop': {'SERVICE_ID': '...', 'USERNAME': '...', 'PASSWORD': '...',
'ALLOWED_IPS': ['...'], 'IS_SANDBOX': False},
},
'IP_HEADER': 'HTTP_X_REAL_IP', # where your proxy puts the caller's address
'BEHIND_CLOUDFLARE': True, # believe CF-Connecting-IP from Cloudflare only
},
}
- Separate books. Every row in
paymentscarries itskassa, and every lookup is scoped to the kassa that called. One kassa never sees, performs, cancels or reports another's transactions, and the same provider transaction id may exist once per kassa. KASSA_FIELDnames a field on your account model that holds the kassa it must be paid through. A call from any other kassa is told the account does not exist. A Paynet kassa may setACCOUNT_KASSAwhen the value stored on accounts differs from its key inKASSAS.- Sandbox (
IS_SANDBOX, Paynet and Uzum). Payments are recorded, butsandbox_payment(params, transaction)is called instead ofsuccessfully_payment. The account stays payable for the provider's tester, and sandbox rows stay out of live statements. - Paynet passwords.
ChangePasswordstores the new password inCREDENTIAL_MODEL(by default the bundledPaynetCredential, tablepaynet_service_credentials). The settings'PASSWORDapplies until Paynet rotates it. A wrong login answers error 412 with HTTP 401. - Uzum IP allowlist.
ALLOWED_IPSis per kassa. The caller is read fromIP_HEADER(defaultREMOTE_ADDR). WithBEHIND_CLOUDFLARE,CF-Connecting-IPis believed only when the request itself came from one of Cloudflare's published edge ranges.
The single-kassa settings shown earlier keep working unchanged. Their rows
have kassa = ''.
Hooks run in the payment's transaction
successfully_payment (and sandbox_payment) run inside the same database
transaction as the row that records the payment. If a hook raises, nothing is
marked paid and the provider gets an error, so it retries: Payme -32400,
Click -7, Paynet 102, Uzum 99999.
Payme's SetFiscalData is supported. The receipt is kept in the
transaction's extra_data['fiscal'], then
fiscal_data_received(params, transaction) is called.
FastAPI Integration
- Set up the database models:
from datetime import datetime, timezone
from sqlalchemy import create_engine, Column, Integer, String, Numeric, DateTime
from sqlalchemy.orm import declarative_base, sessionmaker
from paytechuz.integrations.fastapi import run_migrations
SQLALCHEMY_DATABASE_URL = "sqlite:///./payments.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
Base = declarative_base()
class Order(Base):
__tablename__ = "orders"
id = Column(Integer, primary_key=True, index=True)
product_name = Column(String, index=True)
amount = Column(Numeric(12, 2))
status = Column(String, default="pending")
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
# Create the paytechuz payments table
run_migrations(engine)
# Create your own tables
Base.metadata.create_all(bind=engine)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
- Create the webhook routes:
from fastapi import FastAPI, Request, Depends
from sqlalchemy.orm import Session
from paytechuz.integrations.fastapi import PaymeWebhookHandler, ClickWebhookHandler
app = FastAPI()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
class CustomPaymeWebhookHandler(PaymeWebhookHandler):
def successfully_payment(self, params, transaction):
order = self.db.query(Order).filter(Order.id == transaction.account_id).first()
order.status = "paid"
self.db.commit()
def cancelled_payment(self, params, transaction):
order = self.db.query(Order).filter(Order.id == transaction.account_id).first()
order.status = "cancelled"
self.db.commit()
class CustomClickWebhookHandler(ClickWebhookHandler):
def successfully_payment(self, params, transaction):
order = self.db.query(Order).filter(Order.id == transaction.account_id).first()
order.status = "paid"
self.db.commit()
def cancelled_payment(self, params, transaction):
order = self.db.query(Order).filter(Order.id == transaction.account_id).first()
order.status = "cancelled"
self.db.commit()
@app.post("/payments/payme/webhook")
async def payme_webhook(request: Request, db: Session = Depends(get_db)):
handler = CustomPaymeWebhookHandler(
db=db,
payme_id="your_merchant_id",
payme_key="your_merchant_key",
account_model=Order,
account_field='id',
amount_field='amount',
)
return await handler.handle_webhook(request)
@app.post("/payments/click/webhook")
async def click_webhook(request: Request, db: Session = Depends(get_db)):
handler = CustomClickWebhookHandler(
db=db,
service_id="your_service_id",
secret_key="your_secret_key",
account_model=Order,
account_field='id',
amount_field='amount',
one_time_payment=True,
)
return await handler.handle_webhook(request)
The FastAPI integration currently ships webhook handlers for Payme and Click. Uzum, Paynet and Octo webhooks are available for Django.
The transaction table
Both integrations record every callback in one table, payments, so you rarely
need provider-specific queries.
from paytechuz.integrations.django.models import PaymentTransaction
paid = PaymentTransaction.objects.filter(
gateway=PaymentTransaction.PAYME,
state=PaymentTransaction.SUCCESSFULLY,
)
| Column | Meaning |
|---|---|
gateway |
payme, click, uzum, paynet or octo |
kassa |
the kassa that took the call; '' in a single-kassa setup |
transaction_id |
the provider's id; unique together with gateway and kassa |
account_id |
your order's primary key, as a string |
amount |
in som, not tiyin |
state |
see below |
reason |
provider cancellation code, when one was sent |
extra_data |
the raw callback payload |
created_at / performed_at / cancelled_at |
timestamps |
States:
| Value | Constant | Meaning |
|---|---|---|
0 |
CREATED |
row exists, nothing confirmed |
1 |
INITIATING |
provider created the transaction |
2 |
SUCCESSFULLY |
paid |
-1 |
CANCELLED_DURING_INIT |
cancelled before it was performed |
-2 |
CANCELLED |
cancelled after a successful payment |
Note on the Django app label. The integration is installed as
paytechuz.integrations.django, so Django derives the app labeldjangoand its migrations are recorded under that name. This is whymakemigrationsoutput anddjango_migrationsrows mention an app calleddjango.
Project layout
paytechuz/
├── core/ # shared base classes, HTTP client, exceptions, utils
├── gateways/ # one package per provider (client + constants)
│ ├── payme/ click/ uzum/ paynet/ octo/
└── integrations/
├── django/ # models, admin, signals, migrations
│ ├── webhooks/ # one webhook handler per provider
│ └── views.py # CSRF-exempt base views
└── fastapi/ # SQLAlchemy models, pydantic schemas, handlers
docs/abstract_webhook.md describes the shared webhook contract and the
checklist to follow when adding a new provider.
Development
make install-dev # editable install with django, fastapi and dev extras
make test # run the test suite
make lint # flake8
make build # build sdist + wheel into dist/
Contributing
Pull requests are welcome. CONTRIBUTING.md covers the setup,
what CI checks, and the extra care that amount handling and webhook protocols
need. docs/abstract_webhook.md is the contract to follow when adding a
gateway.
Found a security issue? Do not open an issue — see SECURITY.md.
License
MIT — see LICENSE.
Metadata
Release files for paytechuz 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| paytechuz-0.5.0.tar.gz | 91.2 kB | Without provenance | Details for paytechuz-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paytechuz-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for paytechuz-0.5.0-py3-none-any.whl |
Total release size: 179.1 kB
Release files / paytechuz-0.5.0.tar.gz
| Download URL | paytechuz-0.5.0.tar.gz |
|---|---|
| Size | 91.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dbb4dab49d073cb0d4539a68d80984c3bb88c7c69f40577c36d5151feae993f8
|
|
BLAKE2b-256 checksum How to use checksums |
474111df111e174f51b5cf7919cffe18ab462e786012570ee701348ad57f2976
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / paytechuz-0.5.0-py3-none-any.whl
| Download URL | paytechuz-0.5.0-py3-none-any.whl |
|---|---|
| Size | 87.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2a1d9ca300f6131b37ba4eddce39c4c9c55d35d9ca9b8edb887fa13f07a4bf4
|
|
BLAKE2b-256 checksum How to use checksums |
a880890bbd27471da26c09a011453aaaa23b94bbdedcac4b4accdc5cd9d8632f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for paytechuz 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.