---
title: Uzum Integratsiyasi
description: Uzum to'lov tizimini PayTechUZ yordamida Python va Django bilan integratsiya qilish. Kod namunalari bilan to'liq qo'llanma.
source: https://pay-tech.uz/docs/integrations/uzum
---

# Uzum Integratsiyasi

Uzum — O'zbekistonda tez rivojlanayotgan to'lov tizimi. Ushbu qo'llanma Uzum'ni PayTechUZ bilan qanday integratsiya qilishni ko'rsatadi.

## O'rnatish

```bash
pip install paytechuz
```

## Asosiy Foydalanish

### Gateway Yaratish

```python
from paytechuz.gateways.uzum.client import UzumGateway

# Uzum gatewayni ishga tushirish (Biller/open-service)
uzum = UzumGateway(
    service_id="your_service_id",  # Uzum Service ID
    is_test_mode=True  # Production muhitida False qilib belgilang
)
```

### To'lov Yaratish

```python
# Uzum Biller to'lov havolasini yaratish
# URL formati: https://www.uzumbank.uz/open-service?serviceId=...&order_id=...&amount=...&redirectUrl=...
uzum_link = uzum.create_payment(
    id="order_123",  # Buyurtma ID (order_id parametri)
    amount=100000,  # so'mdagi summa (tiyinga o'tkaziladi)
    return_url="https://example.com/callback"  # redirectUrl parametri
)
# Natija: https://www.uzumbank.uz/open-service?serviceId=your_service_id&order_id=order_123&amount=10000000&redirectUrl=https%3A%2F%2Fexample.com%2Fcallback
```

## Django Integratsiyasi

### Settings.py

`PAYTECHUZ` sozlamalariga `UZUM` konfiguratsiyasini qo'shing:

```python
# settings.py
INSTALLED_APPS = [
    # ...
    'paytechuz.integrations.django',
]

PAYTECHUZ = {
    # ... boshqa gatewaylar
    'UZUM': {
        'SERVICE_ID': 'your_service_id',  # Biller URL uchun Uzum Service ID
        'USERNAME': 'your_uzum_username',  # Webhook Basic Auth uchun
        'PASSWORD': 'your_uzum_password',  # Webhook Basic Auth uchun
        'ACCOUNT_MODEL': 'your_app.models.Order',
        'ACCOUNT_FIELD': 'id',  # yoki 'order_id'
        'AMOUNT_FIELD': 'amount',
        'ONE_TIME_PAYMENT': True, # Set to False if you want to allow multiple payments for the same invoice
        'IS_TEST_MODE': True,  # Production da False qilib belgilang
    }
}
```

### Views.py

`BaseUzumWebhookView` dan meros olib webhook view yarating:

```python
# views.py
from paytechuz.integrations.django.views import BaseUzumWebhookView
from .models import Order

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()
```

### URLs.py

Webhook URL ni qo'shing. E'tibor bering, Uzum webhooklari URL yo'lida `action` parametridan foydalanadi:

```python
# urls.py
from django.urls import path
from .views import UzumWebhookView

urlpatterns = [
    # ...
    path('payments/webhook/uzum/<str:action>/', UzumWebhookView.as_view(), name='uzum_webhook'),
]
```

## Qo'shimcha Ma'lumot

- [PayTechUZ GitHub Repozitoriysi](https://github.com/PayTechUz/paytechuz)
- [Django Integratsiyasi](./django)
- [FastAPI Integratsiyasi](./fastapi)
