---
title: Payme Integration
description: Integrate Payme (Paycom) into a Python project with PayTechUZ — gateway setup, payment links, JSON-RPC webhooks, fiscal receipts, Django and FastAPI examples.
source: https://pay-tech.uz/en/docs/integrations/payme
---

# Payme Integration

Payme is one of the most widely used payment systems in Uzbekistan. This guide shows
how to integrate Payme with PayTechUZ.

## Installation

```bash
pip install paytechuz
```

## Basic usage

### Create a gateway

```python
import os
from paytechuz.gateways.payme import PaymeGateway

gateway = PaymeGateway(
    payme_id="your_payme_id",
    payme_key="your_payme_key",
    is_test_mode=True,  # True for testing, False for production
)
```

### Create a payment

```python
payment = gateway.create_payment(
    id="12345",          # Invoice ID
    amount=50000,        # 500.00 UZS (in tiyin)
    return_url="https://example.com/return",
    account_field_name="id"  # Required: field name used for the account lookup
)

print(f"Payment URL: {payment}")
# Redirect the user to the payment URL
```

### Check payment status

```python
status = gateway.check_payment("transaction_id")
print(f"Status: {status['status']}")
```

## Webhooks

Webhooks are handled through the framework integrations — `BasePaymeWebhookView` for
Django and `PaymeWebhookHandler` for FastAPI. The JSON-RPC methods, Basic auth check
and transaction state are managed for you; you only override the event methods.

See the sections below.

## Django integration

### Settings.py

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

PAYTECHUZ = {
    'PAYME': {
        'PAYME_ID': 'your_payme_id',
        'PAYME_KEY': 'your_payme_key',
        'ACCOUNT_MODEL': 'shop.models.Order',
        'ACCOUNT_FIELD': 'id',
        'AMOUNT_FIELD': 'amount',
        'IS_TEST_MODE': True,
    }
}
```

### Creating a payment

Building the gateway from settings:

```python
from django.conf import settings
from paytechuz.gateways.payme import PaymeGateway

# Build the gateway from settings
gateway = PaymeGateway(
    payme_id=settings.PAYTECHUZ['PAYME']['PAYME_ID'],
    payme_key=settings.PAYTECHUZ['PAYME']['PAYME_KEY'],
    is_test_mode=settings.PAYTECHUZ['PAYME']['IS_TEST_MODE']
)

# Create the payment
payment_url = gateway.create_payment(
    id=order.id,
    amount=order.amount,
    return_url='https://example.com/payment/callback',
    account_field_name=settings.PAYTECHUZ['PAYME']['ACCOUNT_FIELD']  # From settings
)
```

### Views.py

```python
from paytechuz.integrations.django.views import BasePaymeWebhookView
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
        """
        Return additional data for CheckPerformTransaction (fiscal receipt)

        You can override this method to return additional data for fiscal receipt
        """
        return {
            "additional": {"first_name": account.user.first_name}, # optional
            "detail": { # optional
                "receipt_type": 0,
                "shipping": {"title": "Yetkazib berish", "price": 10000},
                "items": [
                    {
                        "discount": 0,
                        "title": account.product_name,
                        "price": account.amount,
                        "count": 1,
                        "code": "00001",
                        "units": 1,
                        "vat_percent": 0,
                        "package_code": "123456"
                    }
                ]
            }
        }
```

### URLs.py

```python
from django.urls import path
from .views import PaymeWebhookView

urlpatterns = [
    path('webhooks/payme/', PaymeWebhookView.as_view(), name='payme_webhook'),
]
```

## FastAPI integration

```python
from fastapi import FastAPI, Request
from paytechuz.gateways.payme import PaymeGateway
from paytechuz.integrations.fastapi import PaymeWebhookHandler
import os

app = FastAPI()

# Create the gateway
payme = PaymeGateway(
    payme_id=os.getenv('PAYME_ID'),
    payme_key=os.getenv('PAYME_KEY'),
    is_test_mode=True
)

@app.post("/payment/create")
async def create_payment():
    payment_url = payme.create_payment(
        id="12345",
        amount=50000,
        return_url="https://example.com/return",
        account_field_name="id"  # Required: field name used for the account lookup
    )
    return {"payment_url": payment_url}

@app.post("/webhooks/payme")
async def webhook(request: Request):
    handler = PaymeWebhookHandler(
        payme_id=os.getenv('PAYME_ID'),
        payme_key=os.getenv('PAYME_KEY'),
        account_model=Order,
        account_field='id',
        amount_field='amount'
    )
    return await handler.handle_webhook(request)
```

## Configuration

### Test mode

Use these credentials for testing:
- **Payme ID**: `test_payme_id`
- **Payme Key**: `test_payme_key`
- **Test card**: `8600 0691 9540 6311`

### Production mode

1. Register at [Payme Business](https://business.payme.uz)
2. Get your production credentials
3. Set `is_test_mode=False`

## Error handling

```python
from paytechuz.core.exceptions import PaymentException

try:
    payment = gateway.create_payment(
        id="12345",
        amount=50000,
        return_url="https://example.com/return",
        account_field_name="id"  # Required: field name used for the account lookup
    )
except PaymentException as e:
    print(f"Payme error: {e.code} - {e.message}")
```

## Further reading

- [Payme official documentation](https://developer.payme.uz)
- [PayTechUZ GitHub repository](https://github.com/PayTechUz/paytechuz)
- [Django Integration](./django)
- [FastAPI Integration](./fastapi)
