Django API connector for Tegro Money's HTTP APIs.
Put simply, django-tegro-money
is the lightweight one-stop-shop module for the Tegro Money's HTTP APIs.
It was designed with the following vision in mind:
I wanted to build my own Django-dedicated connector to Tegro Money the system for accepting online payments with very little external resources. The goal of the connector is to provide entrepreneurs and developers with an easy-to-use high-performing module that has an active issue and discussion board leading to consistent improvements.
Tegro Money
is being actively developed, and new API changes should arrive on Tegro Money
very quickly. Tegro Money
uses requests
for its methods, alongside other built-in modules. Anyone is welcome to branch/fork the repository and add their own upgrades. If you think you've made substantial improvements to the module, submit a pull request, so we'll gladly take a look.
django-tegro-money
requires Django 3.2 or higher and Python 3.8 or higher.
The module can be installed manually or via PyPI with pip
:
pip install django-tegro-money
Add django-tegro-money
to the INSTALLED_APPS
in your settings.py
:
INSTALLED_APPS = [
...,
'django_tegro_money',
...,
]
Add an entry to your urls.py
:
urlpatterns += [
path('', include('django_tegro_money.urls')),
]
Run migration:
python manage.py migrate
The first before using django-tegro-money
you must register with Tegro Money
. Do it ....
Then you must add a store. Do it ....
You can find more information here.
NOTICE! Specify /payment_status/
as Notification URL
:
Notification URL
URL: https://<your_site>/payment_status/
Add secret parameters of your store (Shop ID
, Secret KEY
and API KEY
) in your settings.py
(it's best to store secret settings locally):
TEGRO_MONEY_SHOP_ID = <Shop ID>
TEGRO_MONEY_SECRET_KEY = <Secret KEY>
TEGRO_MONEY_API_KEY = <API KEY>
Create TegroMoney
object:
tegro_money = TegroMoney(log_requests=True, timeout=10, max_retries=3, retry_delay=3)
Just use TegroMoney
methods:
# Create order and get payment
# Get data (you can get data from your form)
data = {
"amount": 1200,
"currency": "RUB",
"order_id": "test order",
"payment_system": 5,
"fields": {
"email": "[email protected]",
"phone": "79111231212"
},
"receipt": {
"items": [
{
"name": "test item 1",
"count": 1,
"price": 600
},
{
"name": "test item 2",
"count": 1,
"price": 600
}
]
}
}
# Send request to Tegro Money
try:
result = tegro_money.create_order(**data)
# Save order id from tegro money for future use
tegro_money_order_id = result['data']['id']
# Redirect to payment page
return redirect(result['data']['url'])
except:
pass