Skip to main content

Uzum Integration

Uzum is a fast-growing payment system in Uzbekistan. This guide shows how to integrate Uzum with PayTechUZ.

Installation

pip install paytechuz

Basic usage

Create a gateway

from paytechuz.gateways.uzum.client import UzumGateway

# Initialise the Uzum gateway (Biller/open-service)
uzum = UzumGateway(
service_id="your_service_id", # Uzum Service ID
is_test_mode=True # Set to False in production
)

Create a payment

# Build an Uzum Biller payment link
# URL format: https://www.uzumbank.uz/open-service?serviceId=...&order_id=...&amount=...&redirectUrl=...
uzum_link = uzum.create_payment(
id="order_123", # Order ID (the order_id parameter)
amount=100000, # Amount in so'm (converted to tiyin)
return_url="https://example.com/callback" # The redirectUrl parameter
)
# Result: https://www.uzumbank.uz/open-service?serviceId=your_service_id&order_id=order_123&amount=10000000&redirectUrl=https%3A%2F%2Fexample.com%2Fcallback

Django integration

Settings.py

Add the UZUM block to your PAYTECHUZ settings:

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

PAYTECHUZ = {
# ... other gateways
'UZUM': {
'SERVICE_ID': 'your_service_id', # Uzum Service ID for the Biller URL
'USERNAME': 'your_uzum_username', # For webhook Basic Auth
'PASSWORD': 'your_uzum_password', # For webhook Basic Auth
'ACCOUNT_MODEL': 'your_app.models.Order',
'ACCOUNT_FIELD': 'id', # or '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, # Set to False in production
}
}

Views.py

Create a webhook view by subclassing BaseUzumWebhookView:

# 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

Add the webhook URL. Note that Uzum webhooks carry an action parameter in the path:

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

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

Further reading