Click Integration
Click is a widely used payment system in Uzbekistan. This guide shows how to integrate Click with PayTechUZ.
Installation
pip install paytechuz
Basic usage
Create a gateway
import os
from paytechuz.gateways.click import ClickGateway
gateway = 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, # True for testing, False for production
)
Create a payment
payment = gateway.create_payment(
id="12345", # Invoice ID
amount=500.00, # Amount in UZS
return_url="https://example.com/return"
)
print(f"Payment URL: {payment}")
# Redirect the user to the payment URL
Check payment status
status = gateway.check_payment("transaction_id")
print(f"Status: {status['status']}")
Webhooks
Webhooks are handled through the framework integrations — BaseClickWebhookView for
Django and ClickWebhookHandler for FastAPI. Signature verification, transaction
persistence and the response format are done for you; you only override the event
methods.
See the sections below.
Django integration
Settings.py
INSTALLED_APPS = [
# ...
'paytechuz.integrations.django',
]
PAYTECHUZ = {
'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': 'shop.models.Order',
'ACCOUNT_FIELD': 'id',
'AMOUNT_FIELD': 'amount',
'IS_TEST_MODE': True,
}
}
Views.py
from paytechuz.integrations.django.views import BaseClickWebhookView
from .models import Order
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()
URLs.py
from django.urls import path
from .views import ClickWebhookView
urlpatterns = [
path('webhooks/click/', ClickWebhookView.as_view(), name='click_webhook'),
]
FastAPI integration
from fastapi import FastAPI, Request
from paytechuz.gateways.click import ClickGateway
from paytechuz.integrations.fastapi import ClickWebhookHandler
import os
app = FastAPI()
# Create the gateway
click = ClickGateway(
service_id=os.getenv('CLICK_SERVICE_ID'),
merchant_id=os.getenv('CLICK_MERCHANT_ID'),
merchant_user_id=os.getenv('CLICK_MERCHANT_USER_ID'),
secret_key=os.getenv('CLICK_SECRET_KEY'),
is_test_mode=True
)
@app.post("/payment/create")
async def create_payment():
payment_url = click.create_payment(
id="12345",
amount=500.00,
return_url="https://example.com/return"
)
return {"payment_url": payment_url}
@app.post("/webhooks/click")
async def webhook(request: Request):
handler = ClickWebhookHandler(
service_id=os.getenv('CLICK_SERVICE_ID'),
secret_key=os.getenv('CLICK_SECRET_KEY'),
account_model=Order
)
return await handler.handle_webhook(request)
Configuration
Test mode
Use these credentials for testing:
- Service ID:
test_service_id - Merchant ID:
test_merchant_id - Test card:
8600 0691 9540 6311
Production mode
- Register at Click Business
- Get your production credentials
- Set
is_test_mode=False
Error handling
from paytechuz.core.exceptions import PaymentException
try:
payment = gateway.create_payment(
id="12345",
amount=500.00,
return_url="https://example.com/return"
)
except PaymentException as e:
print(f"Click error: {e.code} - {e.message}")
Webhook response codes
Click expects specific response codes:
0— Success-1— Signature verification failed-2— Invalid amount parameter-3— Action not found-4— Already paid-5— User does not exist-6— Transaction does not exist-7— Failed to update user-8— Error in request from Click-9— Transaction cancelled