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 Gateway
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 test, False for production
)
Create Payment
payment = gateway.create_payment(
id="12345", # order ID
amount=500.00, # amount in UZS
return_url="https://example.com/return"
)
print(f"Payment URL: {payment}")
# Redirect user to payment URL
Check Payment Status
status = gateway.check_payment("transaction_id")
print(f"Status: {status['status']}")
Webhook
from paytechuz.gateways.click.webhook import ClickWebhookHandler
webhook_handler = ClickWebhookHandler(
service_id="your_service_id",
secret_key="your_secret_key"
)
def process_webhook(request_data):
response = webhook_handler.handle_webhook(request_data)
if response['error'] == 0:
# Payment successful
print("Payment successful!")
return response
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 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
For testing, use these credentials:
- 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.exceptions import ClickException
try:
payment = gateway.create_payment(
id="12345",
amount=500.00,
return_url="https://example.com/return"
)
except ClickException as e:
print(f"Click error: {e}")
Webhook Response Codes
Click webhook expects specific response codes:
0
- Success-1
- Sign check failed-2
- Incorrect parameter amount-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