Welcome to payme-pkg, the open source payme SDK for Python.
You can use it for test and production mode. Join our community and ask everything you need.
Visit the full documentation for Merchant and Subscribe API
pip install payme-pkg
Add 'payme'
in to your settings.py
INSTALLED_APPS = [
...
'payme',
...
]
Add 'payme'
credentials inside to settings.py
One time payment (Однаразовый платеж) configuration settings.py
Example project: https://github.com/PayTechUz/shop-backend
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
Multi payment (Накопительный) configuration settings.py
Example project: Coming soon
PAYME_ID = "your-payme-id"
PAYME_KEY = "your-payme-key"
PAYME_ACCOUNT_FIELD = "id"
PAYME_ACCOUNT_MODEL = "clients.models.Client"
PAYME_ONE_TIME_PAYMENT = False
Create a new View that about handling call backs
from payme.views import PaymeWebHookAPIView
class PaymeCallBackAPIView(PaymeWebHookAPIView):
def handle_created_payment(self, params, result, *args, **kwargs):
"""
Handle the successful payment. You can override this method
"""
print(f"Transaction created for this params: {params} and cr_result: {result}")
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
python3 manage.py makemigrations && 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.
Example to generate link:
- Input
from payme import Payme
payme = Payme(payme_id="your-payme-id")
pay_link = payme.initializer.generate_pay_link(id=123456, amount=5000, return_url="https://example.com")
print(pay_link)
- Output
https://checkout.paycom.uz/bT15b3VyLXBheW1lLWlkO2FjLmlkPTEyMzQ1NjthPTUwMDAwMDtjPWh0dHBzOi8vZXhhbXBsZS5jb20=
Example to generate fallback link:
- Input
The ID in the fallback is different from the merchant ID. You can get the ID from the Payme team.
from payme import Payme
payme = Payme(payme_id="your-payme-id", fallback_id="your-fallback-id")
form_fields = {
"driver_id": 12345,
"amount": 1000
}
fallback_link = payme.initializer.generate_fallback_link(form_fields) # form field is optional
print(fallback_link)
- Output
https://payme.uz/fallback/merchant/?id=examplelinkgenerated&driver_id=12345&amount=1000