Welcome to payme-pkg, the Payme SDK for Python.
You can use it for test and production mode. Join our community and ask everything you need.
pip install payme-pkg- Installation
- Django Integration
- Payme Client SDK
Add 'payme' in to your settings.py
INSTALLED_APPS = [
...
'payme',
...
]Add 'payme' credentials inside to settings.py (if you have api key)
One time payment (Однаразовый платеж) configuration settings.py
Example project: https://github.com/PayTechUz/shop-backend
PAYTECH_API_KEY = "your-api-key" # contact with @muhammadali_me on Telegram for getting api key
PAYME_ID = "your-payme-id"
PAYME_KEY = "your-payme-key"
PAYME_ACCOUNT_FIELD = "order_id"
PAYME_AMOUNT_FIELD = "total_amount"
PAYME_ACCOUNT_MODEL = "orders.models.Orders"
PAYME_ONE_TIME_PAYMENT = True
PAYME_DISABLE_ADMIN = False # (optionally configuration if you want to disable change to True)Create a new View that about handling call backs
from payme.views import PaymeWebHookAPIView
class PaymeCallBackAPIView(PaymeWebHookAPIView):
def handle_successfully_payment(self, params, result, *args, **kwargs):
"""
Handle the successful payment. You can override this method
"""
print(f"Transaction successfully performed for this params: {params} and performed_result: {result}")
def handle_cancelled_payment(self, params, result, *args, **kwargs):
"""
Handle the cancelled payment. You can override this method
"""
print(f"Transaction cancelled for this params: {params} and cancelled_result: {result}")Add a payme path to core of urlpatterns:
from django.urls import path
from django.urls import include
from your_app.views import PaymeCallBackAPIView
urlpatterns = [
...
path("payment/update/", PaymeCallBackAPIView.as_view()),
...
]Run migrations
python manage.py migrate🎉 Congratulations you have been integrated merchant api methods with django, keep reading docs. After successfull migrations check your admin panel and see results what happened.
The Payme SDK provides a unified client interface for working with all Payme services.
Initialize the Payme client with your credentials:
from payme import Payme
# Basic initialization (for Cards API and Payment Links)
payme = Payme(
payme_id="your-payme-id",
is_test_mode=True, # Optional: defaults to False
license_api_key="your-license-key" # Contact @muhammadali_me on Telegram
)
# Full initialization (for all features including Receipts API)
payme = Payme(
payme_id="your-payme-id",
payme_key="your-payme-key", # Required for Receipts API
is_test_mode=True,
license_api_key="your-license-key"
)Manage card tokenization and verification.
Create a new card token.
response = payme.cards_create(
number="8600495473316478",
expire="0399", # MMYY format
save=True, # Optional: save card for future use
timeout=10 # Optional: request timeout in seconds
)
print(response.result.card.token) # Card token
print(response.result.card.number) # Masked card numberRequest a verification code for a card.
response = payme.cards_get_verify_code(
token="card-token",
timeout=10
)
print(response.result.sent) # True if code was sent
print(response.result.phone) # Phone number where code was sentVerify a card with the code received via SMS.
response = payme.cards_verify(
token="card-token",
code="666666", # Code from SMS
timeout=10
)
print(response.result.card.verify) # True if verifiedCheck the status of a card.
response = payme.cards_check(
token="card-token",
timeout=10
)
print(response.result.card.verify) # Verification statusRemove a card token.
response = payme.cards_remove(
token="card-token",
timeout=10
)
print(response.result.success) # True if removedRun comprehensive tests for card operations.
payme.cards_test()Manage payment receipts (requires payme_key).
Create a new payment receipt.
response = payme.receipts_create(
account={"order_id": 12345},
amount=50000, # Amount in tiyins (50000 tiyins = 500 UZS)
description="Payment for order #12345", # Optional
detail={ # Optional
"items": [
{"name": "Product 1", "price": 25000, "quantity": 1},
{"name": "Product 2", "price": 25000, "quantity": 1}
]
},
timeout=10
)
print(response.result.receipt._id) # Receipt IDPay a receipt using a card token.
response = payme.receipts_pay(
receipts_id="receipt-id",
token="card-token",
timeout=10
)
print(response.result.receipt.state) # Payment state (4 = paid)Send receipt details to a phone number.
response = payme.receipts_send(
receipts_id="receipt-id",
phone="998901234567",
timeout=10
)
print(response.result.success) # True if sentCancel a receipt.
response = payme.receipts_cancel(
receipts_id="receipt-id",
timeout=10
)
print(response.result.receipt.state) # State (50 = cancelled)Check the status of a receipt.
response = payme.receipts_check(
receipts_id="receipt-id",
timeout=10
)
print(response.result.state) # Current stateGet detailed information about a specific receipt.
response = payme.receipts_get(
receipts_id="receipt-id",
timeout=10
)
print(response.result.receipt) # Receipt detailsGet all receipts within a time range.
response = payme.receipts_get_all(
count=10, # Number of receipts to retrieve
from_=1609459200000, # Start timestamp (milliseconds)
to=1640995200000, # End timestamp (milliseconds)
offset=0, # Pagination offset
timeout=10
)
for receipt in response.result:
print(receipt._id, receipt.amount)Set fiscal data for a receipt.
response = payme.receipts_set_fiscal_data(
receipt_id="receipt-id",
qr_code_url="https://ofd.uz/check?t=123&s=456&r=789&c=2024",
timeout=10
)
print(response.result.success) # True if setRun comprehensive tests for receipt operations.
payme.receipts_test()Generate payment links for customers.
Generate a payment link for checkout.
pay_link = payme.generate_pay_link(
id=12345, # Account ID
amount=5000, # Amount in UZS (will be converted to tiyins)
return_url="https://example.com/success"
)
print(pay_link)
# Output: https://checkout.paycom.uz/bT1...Generate a fallback payment link with custom form fields.
fallback_link = payme.generate_fallback_link(
form_fields={ # Optional
"driver_id": 12345,
"amount": 1000
}
)
print(fallback_link)
# Output: https://payme.uz/fallback/merchant/?id=...&driver_id=12345&amount=1000Note: The fallback ID is different from the merchant ID. Contact the Payme team to get your fallback ID.