Skip to content

firdavsDev/payme-uz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Payme API Client

This package provides a clean, testable, production-ready asynchronous Payme API client for Python (Django or any ASGI/async app).

βœ… SOLID
βœ… DRY
βœ… Type-safe (with PaymeErrorCode enum)
βœ… Built-in retries + logging
βœ… Gracefully closes aiohttp session
βœ… Unit-test ready


Structure


.
β”œβ”€β”€ __init__.py
β”œβ”€β”€ examples
β”‚   └── example.py
β”œβ”€β”€ Makefile
β”œβ”€β”€ logs
β”‚   └── payme.log
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements-dev.txt
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example
β”œβ”€β”€ pytest.ini
β”œβ”€β”€ src
β”‚   └── payme
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ enums.py
β”‚       β”œβ”€β”€ log.py
β”‚       └── client.py
└── tests
    └── test_payme_client.py


Installation

Install via pip (soon to be available)

pip install payme-uz

Install from source (development version)

git clone git@github.com:firdavsDev/payme-uz.git
cd payme-uz
pip install -r requirements-dev.txt
pip install -e .

Usage

Service example

from payme.client import PaymeAPIClient
from payme.enums import PaymeErrorCode

CARD_NUMBER = "8600123456789012"
CARD_EXPIRE = "2504"  # MMYY
COURSE_PRICE = 1000  # so'm
RETURN_URL = "https://yourapp.com/return"

USER_ID = 12345  # Example user ID

#===================================================

# Step 1️⃣ Create card
print("\n1️⃣ Creating card...")
payme_client = PaymeAPIClient()
response = await payme_client.create_card(CARD_NUMBER, CARD_EXPIRE, save=False)

#===================================================

# Get the token and send SMS code
token = response["result"]["card"]["token"]
response = await payme_client.get_card_verify_code(token)
phone = response["result"]["phone"]

print(f"βœ… Card created. Token: {token}")
print(f"πŸ“² SMS sent to: {phone}")

#===================================================

# Step 2️⃣ Get verify code (usually this is separate API call after user submits SMS code)
print("\n2️⃣ Verifying card...")
SMS_CODE = input(f"Enter SMS code sent to {phone}: ").strip()
verify = await payme_client.verify_card(code=SMS_CODE, token=token)
token_response = verify["result"]["card"]["token"]

#===================================================

# Step 3️⃣ Create receipt
print("\n3️⃣ Creating receipt...")

amount = COURSE_PRICE * 100  # Payme API uses "tiyin", so multiply by 100
receipt_response = await payme_client.create_receipt(
    order_id=str(USER_ID),
    amount=Decimal(amount),
    # order_type="course_payment"  # Example order type
)

#===================================================

# Step 4️⃣ Pay receipt
print("\n4️⃣ Paying receipt...")
receipt_id = receipt_response["result"]["receipt"]["_id"]
pay_response = await payme_client.pay_receipt(receipt_id, token)
paid_amount = pay_response["result"]["receipt"]["amount"]
print(f"βœ… Transaction successful! Amount paid: {paid_amount / 100:.2f} so'm")

#===================================================

# Step 5️⃣ Close sessions
print("\n5️⃣ Closing Payme client session...")
await payme_client.close()

# open /examples/example.py

Testing

pytest tests -v
pytest --cov=payme --cov-report=term-missing tests/ -v
pytest --cov=payme --cov-report=html tests/ -v
open htmlcov/index.html

Environment variables

e.g. using a .env file:

# Set to "true" for production, "false" for test environment
PAYME_ENV=false

# Your Payme API token
PAYME_TOKEN=your_payme_token_here

# Your Payme secret key
PAYME_SECRET_KEY=your_secret_key_here

# Account keys (used for receipts)
PAYME_ACCOUNT_KEY_1=your_account_key_1
PAYME_ACCOUNT_KEY_2=order_type

Notes

  • Built-in retry logic with 10 attempts for network errors.
  • Built-in timeout (30 seconds by default).
  • All responses are logged.
  • Session is reusable β€” you must call close() when done.
  • You can inject your own aiohttp.ClientSession for advanced use cases or testing.

Python Tests

About

Asynchronous Payme.uz API Client for Python. Supports Django, FastAPI, Asyncio. Simple integration with cards, transactions, receipts. πŸš€

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages